使用awk截取某时间段内的日志的单行命令

发布时间:2019-10-09编辑:脚本学堂
想从如下的日志内容中,取出文件里面时间是9点到12点的数据:2012-09-05 01:48:47,150 WARN [WorkManager(3)-72] [service.PhoneRangeManager] phone range domain object not found id 1834930

想从如下的日志内容中,取出文件里面时间是9点到12点的数据:
2012-09-05 01:48:47,150 WARN  [WorkManager(3)-72] [service.PhoneRangeManager] phone range domain object not found id 1834930
2012-09-05 02:48:47,293 WARN  [WorkManager(3)-28] [service.PhoneRangeManager] phone range domain object not found id 1834930
2012-09-05 03:50:14,085 WARN  [WorkManager(3)-61] [service.PhoneRangeManager] phone range domain object not found id 1881137
2012-09-05 04:50:14,223 WARN  [WorkManager(3)-67] [service.PhoneRangeManager] phone range domain object not found id 1881137
2012-09-05 05:50:14,361 WARN  [WorkManager(3)-14] [service.PhoneRangeManager] phone range domain object not found id 1881137
2012-09-05 06:51:29,011 WARN  [WorkManager(3)-70] [service.UserAccountLockService] Thread :325 continue to wait for lock of user :13620003572 , signal = TransactionImple < ac,
2012-09-05 07:51:29,011 WARN  [WorkManager(3)-70] [service.UserAccountLockService] Thread :325 continue to wait for lock of user :13620003572 , signal = TransactionImple < ac,
2012-09-05 08:51:29,011 WARN  [WorkManager(3)-70] [service.UserAccountLockService] Thread :325 continue to wait for lock of user :13620003572 , signal = TransactionImple < ac,
2012-09-05 10:51:29,011 WARN  [WorkManager(3)-70] [service.UserAccountLockService] Thread :325 continue to wait for lock of user :13620003572 , signal = TransactionImple < ac,
BasicAction: -3f57fefa:8d29:50463160:ddaee80 status: ActionStatus.RUNNING >, lock :com.wxxr.common.service.UserAccountLockService$Lock@10b3d72
2012-09-05 11:52:02,732 WARN  [WorkManager(3)-46] [service.PhoneRangeManager] phone range domain object not found id 1881137
2012-09-05 12:52:02,873 WARN  [WorkManager(3)-19] [service.PhoneRangeManager] phone range domain object not found id 1881137
2012-09-05 09:52:03,010 WARN  [WorkManager(3)-95] [service.PhoneRangeManager] phone range domain object not found id 1881137

在实践操作中,请务必注意,一条日志可能占两行。

单行命令:linuxjishu/13830.html target=_blank class=infotextkey>awk -F'[ -:]' '$4 >= 9 && $4 <= 12{print;nextline=NR+1}$1$2$3 !~ /d+/ && NR == nextline' data

您可能感兴趣的文章:
shell截取字符串的例子
有关字符串截取的shell脚本(多个方法)
shell 字符串的处理(截取,连接,匹配,替换,翻转)
shell字符串截取的几种方法
使用awk截取某区域的数据的例子
有关shell中字符串截取的方法总结
awk截取某区域数据
截取每小时随机的100条日志的shell脚本
使用awk截取日志-抽取条件在下面