I am new to AWK.
I have a large text file (>3GB). Like to use AWK line command to extract/print selected lines (line #62, #152 and 153) in that order and it iterates every 217 lines till end of record in file.
Tried to search and learn from the net. Tried the below and it does not seem working,
awk '{(for (i=62; i<=NR; i=i+217)||for (i=62; i<=NR; i=i+217)||for (i=62; i<=NR; i=i+217)); print}' file.txt
and
count=62||152||153
awk '{if (++count%217==0) print;}' file.txt
Could you assist to give me some pointers or lead me to any web which might be of help.
I am using this http://www.catonmat.net/blog/wp-content/uploads/2008/09/awk1line.txt to learn.
rgds
Saravanan K
Update #1 – 21 Sept 2012 – 10.40pm
Tried
awk 'NR == 62 || NR == 152 || NR == 153 || NR % 217 == 0 {print $0;}' file.txt
Able to print line #62, #152 and #153 but not all the following iterations e.g #(62+217), #(152+217) and #(153+217) and so on.
Tried the below too, but it is not working well.
awk '(NR == 62 || NR == 152 || NR == 153) && (((NR-62) % 217==0) || ((NR-152) % 217 ==0)|| ((NR-153) % 217==0)) {print $0;}' file.txt
Update #2 – 21 Sept 2012 – 10.55pm — CLOSED
I tried rmunoz idea with some tweaking. It worked like a magic. Thanks for rmunoz, with this I close this topic
awk '(NR - 62) % 217 == 0 || (NR - 152) % 217 == 0 || (NR - 153) % 217 ==0 {print $0;}' file.txt
You can use patterns in AWK this way: