With awk:
awk -v RS='[[:alpha:]]{3} [[:alpha:]]{3} [0-9]{1,2} ([0-9]{2}:?){3} [0-9]{4}:' \
-v ORS='' '{print}' datafile
NOF DOWN BITS = 96 data = 7E 7E 7E 7E 7E 7E 7E 7E 7E 7E 7E 7E
nof_received_data_packets
This works by setting the Record Separator (RS) to a regex that matches strings which look like a date & time followed by a :
, and setting the Output Record Separator (ORS) to empty.
Then it just prints each "record".
It works with any date & time, assuming only that short Month names and short Day names are always three letters long, and that the date format is always going to be Day Month Daynum HH:MM:SS YYYY
.
With sed:
sed -E 's/[[:alpha:]]{3} [[:alpha:]]{3} [0-9]{1,2} ([0-9]{2}:?){3} [0-9]{4}://g' \
datafile
This use the same date-matching regex to remove everything that looks like a date & time followed by a :
.
With perl:
perl -p -e 's/\w{3} \w{3} \d{1,2} (\d{2}:?){3} \d{4}://g' datafile
perl regular expressions have some nice shortcuts for specifying "word" characters (\w
), and digits (\d
). The perl version is unicode-aware and should work in any locale.
All three are fairly brute-force scripts. I don't think it's worth the effort of trying anything fancier than that unless the date format was likely to vary from the above. If that was the case, I'd probably write something in perl to scan substrings of each line using the Date::Parse
module.
The sed
and awk
versions require GNU sed
and GNU awk
, or at least versions of them that understand {n,m}
regular expression repetition counts.