1. 程式人生 > 其它 >linux 按時間檢視日誌

linux 按時間檢視日誌

2019獨角獸企業重金招聘Python工程師標準>>> hot3.png

linux 按時間檢視日誌

log4j日誌格式如下

  INFO  2017-01-19 16:37:24 com.chaoxing.subject.jobs.SubjectJobFromKafka offset:17700675 message:{"topic":"subjectMetadata","body":"{\"createtime\":1484025855000,\"id\":94929680,\"name\":\"英語一輪複習\",\"dtype\":\"Course\",\"belongschoolid\":\"10019\",\"imageurl\":\"http://p.ananas.chaoxing.com/star3/258_153c/53cf3d81a310abc6bf2334b3.jpg\",\"puid\":\"29664283\",\"lastedittime\":1484815125000,\"isFiled\":false,\"lastModifyTime\":1484815125000,\"author\":\"王婷\",\"courseIdentifier\":\"\",\"provideschool\":\"\",\"courseperiod\":\"\"}","identity":"u","timestamp":1484815126767}
  INFO  2017-01-19 16:37:24 com.chaoxing.subject.jobs.SubjectJobFromKafka offset:17700676 message:{"topic":"subjectMetadata","body":"{\"createtime\":1472462104000,\"id\":90223641,\"name\":\"安徒生童話精選\",\"dtype\":\"Course\",\"belongschoolid\":\"1467\",\"imageurl\":\"http://p.ananas.chaoxing.com/star3/270_169c/56839107498e69718a39cf6f.jpg\",\"puid\":\"25419153\",\"lastedittime\":1484815126000,\"isFiled\":false,\"lastModifyTime\":1484815126000,\"author\":\"超星校園閱讀\",\"courseIdentifier\":\"\",\"provideschool\":\"\",\"courseperiod\":\"\"}","identity":"u","timestamp":1484815126771}
  INFO  2017-01-19 16:37:24 com.chaoxing.subject.jobs.SubjectJobFromKafka offset:17700677 message:{"topic":"subjectMetadata","body":"{\"createtime\":1472462104000,\"id\":90223641,\"name\":\"安徒生童話精選\",\"dtype\":\"Course\",\"belongschoolid\":\"1467\",\"imageurl\":\"http://p.ananas.chaoxing.com/star3/270_169c/56839107498e69718a39cf6f.jpg\",\"puid\":\"25419153\",\"lastedittime\":1484815126000,\"isFiled\":false,\"lastModifyTime\":1484815126000,\"author\":\"超星校園閱讀\",\"courseIdentifier\":\"\",\"provideschool\":\"\",\"courseperiod\":\"\"}","identity":"u","timestamp":1484815127277}
  INFO  2017-01-19 16:37:24 com.chaoxing.subject.jobs.SubjectJobFromKafka offset:17700678 message:{"topic":"subjectMetadata","body":"{\"createtime\":1484811766000,\"id\":95335074,\"name\":\"品牌\",\"dtype\":\"ZT\",\"belongschoolid\":\"1385\",\"imageurl\":\"http://mooc1-api.chaoxing.com/images/phone/img01.jpg\",\"puid\":\"23292834\",\"lastedittime\":1484815127000,\"isFiled\":false,\"lastModifyTime\":1484815127000,\"author\":\"宋元宗\",\"courseIdentifier\":\"\",\"provideschool\":\"\",\"courseperiod\":\"\"}","identity":"u","timestamp":1484815127280}
sed -n '/2017-01-19 16:37:00/,/2017-01-19 16:37:59/p'  SubjectJobLog.log

或者使用正則表示式

sed -n '/2017-01-19 16:[0-9][0-9]:[0-9][0-9]/,/2018-11-17 16:[0-9][0-9]:[0-9][0-9]/p'  SubjectJobLog.log

轉載於:https://my.oschina.net/kdy1994/blog/827921