I'm looking for "sort -z" (supported only in GNU) equivalent in Solaris, so I could have multi-line "block" support. I want to sort some text by chronological order ( date then time ), and that the sort will not break the text blocks in the process.
Example, I have:
2020-05-15:02:00:00:000 INFO[LF]
2020-05-15:02:00:02:000 INFO[LF]
[HT]some extra data as second line[LF]
[HT]2020-05-15:02:00:01:000 INFO[LF]
[HT]some extra data as second line[LF]
[HT]some extra data as third line[LF]
2020-05-15:02:00:04:000 INFO[LF]
2020-05-15:02:00:03:000 INFO[LF]
- [HT] is horizontal tab key and [LF] is \n
and I wish it to be sorted into
2020-05-15:02:00:00:000 INFO[LF]
2020-05-15:02:00:01:000 INFO[LF]
[HT]extra data as second line[LF]
[HT]some extra data as third line[LF]
2020-05-15:02:00:02:000 INFO[LF]
[HT]extra data as second line[LF]
2020-05-15:02:00:03:000 INFO[LF]
2020-05-15:02:00:04:000 INFO[LF]
on Centos/ubuntu (GNU) I manage to do that with: sort -zt : -k2,2 -k3,3n -k4,4n -k5,5n -k6,6n ( although not sure the milisec is being sorted ok ).
Please note:
- I can't use msort - awk / sed / perl one-liner solutions are welcome.
- each line is ending with LF, multi-line or not.
- Multi lines ( 2nd line including and ahead ) starts with HF "tab" char.
Thanks :-)
sort -z
is to sort NUL-delimited records. Where are the NULs in your input?sort
available asgsort
?