linux - Filter specific lines with a given prefix from a file -
I need to get the line before the last time of the prefix given on the whole file, the command I do Can I use (Sed or any other option)?
For example: (prefix is the first two numbers of each row: for example, (16, 316) (0 312), etc.)
File.txt:
0 312 0
0 312 00 314 0> <31> 315 0
0 315 9380
0 315 0>
0 315 0
should be output:
16 316 32
0 312 2130 9
0 313 32732
0 314 19781
0 315 30388
Thanks
I assume those empty rows that the reality And your file is not in.
tac file.txt | Awk '$ 1' "$ 2! = Prefix {getline; Print; Prefix = $ 1 "" $ 2} "| Tac 16 316 32 312 21309 0 313 32732 0 314 19781 315 30388 Reverse the file. When I see a new prefix, print the next line and then reverse the output.
Comments
Post a Comment