简体   繁体   English

zgrep 文件按升序排列

[英]zgrep files in ascending order

I want to extract info from linux logs which are compressed in files numbered from file.gz to file.50.gz.我想从 linux 日志中提取信息,这些日志压缩在从 file.gz 到 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.然后 zgrep 检查的第一个日志文件是 log.1.gz,然后是 log.10.gz,然后是 log.11.gz,等等。但这与事件的时间顺序混淆了。 Is there a way to either: a) make zgrep check in natural ascending order?有没有办法:a)使 zgrep 按自然升序检查? 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 fi: 2021/10/12-08:27:33.166324)或 b) 根据日期对匹配项进行排序(日志中的每一行都遵循此日期模式 yyyy/mm/dd-hh:mm:ss.mss fi: 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 -> 由于这些日志被提取以脱机工作,然后在 windows 机器 (wsl) 中处理,因此这些文件的最后修改日期/时间对于所有这些文件都是相同的

I was trying things like this but no luck (anyway I believe it would only consider the 10 digit date, leaving the timestamp aside):我正在尝试这样的事情,但没有运气(无论如何我相信它只会考虑 10 位数的日期,将时间戳放在一边):

zgrep -ih error log.* | sort -n -t"-" -k1.7,1.10 -k1.1,1.2 -k1.4,1.5

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.这将是命令zgrep -ih error log.{50..1}.gz log.gz ,它是 zgrep log.50.gz,然后是.49.gz 直到 log.gz。 This way I see the matches with older timestamp first until the newest at the end这样,我首先看到具有较旧时间戳的匹配,直到最后的最新

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM