I want to extract info from linux logs which are compressed in files numbered from file.gz to file.50.gz. Then the first log file zgrep checks is log.1.gz, then log.10.gz, then log.11.gz, etc. But this messes up with the chronology of the events. Is there a way to either: a) make zgrep check in natural ascending order? or b) sort the matches according to the date (each line in the logs follows this date patter yyyy/mm/dd-hh:mm:ss.mss f.i: 2021/10/12-08:27:33.166324)
-> Since these logs are extracted to work offline and then processed in a windows machine (wsl) the date/time of last modification from these files is the same for all of them
I was trying things like this but no luck (anyway I believe it would only consider the 10 digit date, leaving the timestamp aside):
zgrep -ih error log.* | sort -n -t"-" -k1.7,1.10 -k1.1,1.2 -k1.4,1.5
CodePudding user response:
this would be the command zgrep -ih error log.{50..1}.gz log.gz
, it zgreps log.50.gz, then .49.gz until log.gz. This way I see the matches with older timestamp first until the newest at the end