I'm working on a complicated grep
, something like grep -E -i "first|next" *.txt
, and I get results like:
logs.10.txt:2022-10-07 10:33:05.6673 | ClassName | [Info] | Inside function first(), before Unsubscribe() |
logs.10.txt:2022-10-07 10:33:05.6673 | ClassName | [Info] | Inside function first(), after Unsubscribe() |
Now, I would like to order the results, based on timestamp, which looks quite easy:
Prompt> grep ... | sort -t: -k2
... but there's a catch: as you see the "before" and "after" regularly happen within the same tenth of millisecond, and the sort
command switches them:
logs.10.txt:2022-10-07 10:33:05.6673 | ClassName | [Info] | Inside function first(), after Unsubscribe() |
logs.10.txt:2022-10-07 10:33:05.6673 | ClassName | [Info] | Inside function first(), before Unsubscribe() |
I have already tried adding an extra field delimiter to the sort
command, but this does not work:
Prompt> grep ... | sort -t:| -k2
Is it possible to:
- add a length parameter to the
sort
command? (Only sort on the first 24 characters) Or: - add a second field delimiter? (Like the pipe character)