当前位置: > shell编程 >

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

时间:2014-09-15 02:24来源:linux.it.net.cn 作者:it

想从如下的日志内容中,取出文件里面时间是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 :325continue 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

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

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

(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容