fragments

May 17, 2019

一个Shell管道的题目

Last updated at: May 17, 2019

有如下a文件b文件,请使用shell管道命令实现根据a文件17:20~17:35期间doValidatetraceId找寻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]

参考

(98 words)