I have a text file. This file includes characters and numbers as follows:
ANKR00TUR_R_20183240000_01D_30S_MO.rnx: 2018 11 20 00 00 0.0000000 GPS TIME OF FIRST OBS
brmu3350.14o: 2014 12 1 0 0 0.0000000 GPS TIME OF FIRST OBS
KNY12040.14o: 2014 7 23 0 0 0.0000000 GPS TIME OF FIRST OBS
rinex_quantity:grep "TIME OF FIRST OBS" * > time_of_first_epochs
I need to extract only 4 digits numbers and store them into another file as follows:
2018
2014
2014
I applied the following code but it extracts all 4 digit numbers:
grep -Po "\d{4}" data
2018
3240
2018
0000
3350
2014
0000
1204
2014
0000
Your
grep
command was almost correct, you just have to anchor the pattern to match only if there is a word boundary before or after it.Word boundaries are zero-length patterns that match between a word-character (letters, digits, underscore) and a non-word charater (e.g. spaces, other punctuation, line end, and everything else).
In
grep
, you can either do this by surrounding your pattern with\b
, or by using the-w
switch to enable word matching:with miller (http://johnkerl.org/miller/doc) is
As output you will have
Mi input is
I have simply extracted the second column with cut