I have the input log a form:
system 2018-02-05 04:15:49 :: aaaaaaaaaaaaa
system 2018-02-05 04:15:51 :: aaaaaaaaaaaaa
system 2018-02-05 04:15:51 :: aaaaaaaaaaaaa
system 2018-02-05 04:15:52 :: aaaaaaaaaaaaa
system 2018-02-05 04:15:53 :: aaaaaaaaaaaaa
system 2018-02-05 04:20:06 :: ccccccccccccc
system 2018-02-05 04:21:10 :: bbbbbbbbbbbbb
system 2018-02-05 04:21:10 :: ccccccccccccc
system 2018-02-05 04:21:10 :: ccccccccccccc
system 2018-02-05 04:21:10 :: ccccccccccccc
system 2018-02-05 04:23:49 :: bbbbbbbbbbbbb
system 2018-02-05 04:23:49 :: ccccccccccccc
and want to have separated each time block by empty line. Expected output for above input would be:
system 2018-02-05 04:15:49 :: aaaaaaaaaaaaa
system 2018-02-05 04:15:51 :: aaaaaaaaaaaaa
system 2018-02-05 04:15:51 :: aaaaaaaaaaaaa
system 2018-02-05 04:15:52 :: aaaaaaaaaaaaa
system 2018-02-05 04:15:53 :: aaaaaaaaaaaaa
system 2018-02-05 04:20:06 :: ccccccccccccc
system 2018-02-05 04:21:10 :: bbbbbbbbbbbbb
system 2018-02-05 04:21:10 :: ccccccccccccc
system 2018-02-05 04:21:10 :: ccccccccccccc
system 2018-02-05 04:21:10 :: ccccccccccccc
system 2018-02-05 04:23:49 :: bbbbbbbbbbbbb
system 2018-02-05 04:23:49 :: ccccccccccccc
The idea is to form the key that each of the lines are unique with, in your case it is $2
and $3
(i.e. in Awk's context second and third space delimited columns).
We build a unique key($2 $3
) by this combination and while parsing the lines if this combination varied from the subsequent line, we print a new line character (also represented by special variable ORS
or just print ""
in Awk). The below code reflects just that
$ awk '($2 $3)!=p && NR>1 {print ""} {print; p=($2 $3)}' file
system 2018-02-05 04:15:49 :: aaaaaaaaaaaaa
system 2018-02-05 04:15:51 :: aaaaaaaaaaaaa
system 2018-02-05 04:15:51 :: aaaaaaaaaaaaa
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With