bash - Linux: Extract a specified number of lines from text file based on match -
i have text file multiple datasets. have written code searches values (top left 4-letter code) in text file but, need able have script copy out data set number of lines after match ("phhi, etc") found. data values formatted same.
data:
phhi gfs mos guidance 7/13/2015 0000 utc dt /july 13 /july 14 /july 15 / hr 06 09 12 15 18 21 00 03 06 09 12 15 18 21 00 03 06 09 12 18 00 x/n 83 71 84 70 84 tmp 77 76 76 76 76 79 82 81 76 76 74 73 76 80 82 81 76 75 73 76 83 dpt 72 72 72 72 72 72 70 68 70 70 69 69 69 70 70 69 69 69 69 69 69 cld bk ov bk ov ov bk fw fw cl fw bk fw sc sc fw fw fw cl fw sc fw wdr 10 09 06 04 07 09 07 08 07 06 03 03 07 08 07 08 07 07 04 07 08 wsp 04 03 03 03 06 11 16 11 06 08 05 03 04 09 12 09 05 03 03 03 10 p06 5 27 16 0 4 2 4 15 5 6 1 p12 39 21 8 19 7 q06 0 1 0 0 0 0 0 0 0 0 0 q12 1 1 0 1 0 cig 5 4 4 4 4 4 5 8 6 6 6 7 6 6 7 8 7 8 8 8 8 vis 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 obv n n n n n n n n n n n n n n n n n n n n n i interested in pulling data values located on "x/n" line.
to specified number of line of data after match:
grep pattern -a num file where,
pattern pattern matched
num number of line of data taken after match
for example, 3 lines after phhi:
grep "^phhi" -a 3 file output:
phhi gfs mos guidance 7/13/2015 0000 utc dt /july 13 /july 14 /july 15 / hr 06 09 12 15 18 21 00 03 06 09 12 15 18 21 00 03 06 09 12 18 00 x/n 83 71 84 70 84 to x/n line:
grep "^x/n.*" file output:
x/n 83 71 84 70 84
Comments
Post a Comment