2 METEOROLOGICAL DATA VERSION /
8 PR TD HR ZW ZT WD WS RI # / TYPES OF MOD/TYPE/ACC
3979316.8350 1050313.7180 4857065.7030 592.1910 PR SENSOR POS XYZ/H
END OF HEADER
10 1 1 0 0 15 927.9 4.3 99.1
10 1 1 0 1 15 927.9 4.3 99.1
10 1 1 0 2 15 927.9 4.3 99.1
10 1 1 0 15 15 927.9 4.2 99.1
10 1 1 0 16 15 927.9 4.2 99.0
10 1 1 0 30 15 927.7 4.1 99.1
10 1 1 0 31 15 927.7 4.1 99.1
10 1 1 0 45 15 927.5 4.1 99.1
10 1 1 0 46 15 927.5 4.0 99.1
10 1 1 1 0 15 927.4 4.1 99.1
10 1 1 1 1 15 927.4 4.1 99.1
In this example of text data, how can I extract all 0,15,30,45 in 5th column of numeric data orderly, after the "END OF HEADER
" part as follows;
10 1 1 0 0 15 927.9 4.3 99.1
10 1 1 0 15 15 927.9 4.2 99.1
10 1 1 0 30 15 927.7 4.1 99.1
10 1 1 0 45 15 927.5 4.1 99.1
10 1 1 1 0 15 927.4 4.1 99.1
A quick one liner would be:
As fedorqui mentioned in the comment below and even quicker one liner is:
Syntax explaned:
The header is filtered out by only accepting lines that match the items following the match
~
criteria.It is perfectly do-able in
grep
, althoughawk
is the go-to tool for field separated data.With
grep
:10
at the start,([^[:blank:]]+[[:blank:]]+){3}
matches the next 3 fields and then matching 5th field for the desired onesIf you use PCRE (
-P
), you can replace[:blank:]
with\s
, looks good on eyes:Example:
You can do this using
sed
andawk
:(assuming your subject text is in a file called
example.txt
)Attribution - the awk command was taken from steeldriver's comment
Explanation
Sed
/END OF HEADER/
/END OF HEADER/d
means delete the line containing/END OF HEADER/
out of the pattern space, and because its no longer in the pattern space, the next commandp
won't do anythingAwk