I am trying to figure out, how to extract data points from a large matrix (m by n) file. I want to extract data along an inclined straight line, along any row and column of a matrix. Example below is what I want to achieve:
Matrix Example
20 21 22 290 46
7 12 18 13 12
16 15 13 9 4
175 8 9 129 47
I want to extract the values if I draw a straight line along cells (1,1) and (4,4), which would be:
20 12 13 129
similarly, if I draw a straight line between cells (3,1) and (1,3), which would be:
16 12 22
I know, you can use arrays in awk, such as myarray[1,1], myarray[2,2], myarry[3,3],myarray[4,4].
However, this might not be the right solution, as my matrix can be 1000 by 1000.
Can anyone help to write a generic awk code, where I will able to provide the first starting cells and the last starting cells and selecting all the values of the cells that lies within the straight line of the first and the last selected cells. This would help me tremendously. I am a very novice user of awk, and I was told that this could be done easily by awk.
Any help is greatly appreciated!
Thanks.
Matrix Example
20 21 22 290 46
7 12 18 13 12
16 15 13 9 4
175 8 9 129 47
I want to extract the values if I draw a straight line along cells (1,1) and (4,4), which would be:
20 12 13 129
similarly, if I draw a straight line between cells (3,1) and (1,3), which would be:
16 12 22
I know, you can use arrays in awk, such as myarray[1,1], myarray[2,2], myarry[3,3],myarray[4,4].
However, this might not be the right solution, as my matrix can be 1000 by 1000.
Can anyone help to write a generic awk code, where I will able to provide the first starting cells and the last starting cells and selecting all the values of the cells that lies within the straight line of the first and the last selected cells. This would help me tremendously. I am a very novice user of awk, and I was told that this could be done easily by awk.
Any help is greatly appreciated!
Thanks.