有如下a文件
和b文件
,请使用shell管道命令实现根据a文件
中17:20~17:35
期间doValidate
的traceId
找寻b文件
中对应的日志信息:
$ cat a
2019-03-04 17:20:16 doValidate [traceId12]
2019-03-04 17:21:17 doValidate [traceId13]
2019-03-04 17:35:16 doValidate [traceId13]
2019-03-04 18:20:16 doValidate [traceId14]
2019-03-04 19:20:16 doValidate [traceId14]
$ cat b
2019-03-04 17:20:17 xxxxxx2 [traceId12]
2019-03-04 17:21:18 xxxx22dd [traceId13]
2019-03-04 17:35:18 xxxx22dd [traceId13]
2019-03-04 18:20:17 xxxxed [traceId14]
2019-03-04 19:20:17 xxxsdsdfs [traceId14]
答案:
$ sed -n '/2019-03-04 17:20:*/,/2019-03-04 17:35:*/p' a|grep doValidate|awk '{print $4}'|uniq| xargs -I '{}' grep -F '{}' b
2019-03-04 17:20:17 xxxxxx2 [traceId12]
2019-03-04 17:21:18 xxxx22dd [traceId13]
2019-03-04 17:35:18 xxxx22dd [traceId13]
参考
- BASH Programming - Introduction HOW-TO: Pipes
- Make xargs execute the command once for each line of input - Stack Overflow
(98 words)