Hi all,
I am new to awk.
I want to print the line numbers if the column has a particular value.
For example I have:
cat FILE1
COL1 COL2
X114 0
X116 0
X117 0
X120 0
X121 0
X125 0
X126 0
X127 0
X131 1
X132 0
X135 0
X136 0
X137 0
X138 0
X140 0
X141 0
X143 0
X144 0
X146 0
X147 1
X150 0
I want to print the lines having value 1 in column 2.
My output should be
10
21
I tried:
awk -v a=2 -F '\t' 'BEGIN {x=1}; {if (1~$a) print x; x++}' FILE1
But it didnot produce any output.
After trying for a long time, I just added aother column to this file (in excel) with zeros. ie;
cat FILE2
COL1 COL2 0
X114 0 0
X116 0 0
X117 0 0
X120 0 0
X121 0 0
X125 0 0
X126 0 0
X127 0 0
X131 1 0
X132 0 0
X135 0 0
X136 0 0
X137 0 0
X138 0 0
X140 0 0
X141 0 0
X143 0 0
X144 0 0
X146 0 0
X147 1 0
X150 0 0
X152 0 0
Now when I do:
awk -v a=2 -F '\t' 'BEGIN {x=1}; {if (1~$a) print x; x++}' FILE2
I am getting the correct output.
can anyone help me on why awk is not working for FILE1. I have to do the same in 100 files. I am not sure what mistake I had made when working on FILE1 format
Your reply will be very helpful. Thanks in advance