【发布时间】:2015-09-21 19:10:31
【问题描述】:
我想从 ABCD_ERR.LOG 读取时间 7:00:59 和 08:00:59 之间记录的日志,并在这些日志行集中搜索一些字符串并将搜索到的输出行存储到 output.txt。但我想在输出线前面加上 inputfilename ie.ABCD_ERR.LOG。 例如, ABCD_ERR.LOG 包含类似的日志
Server 07972 006856 06:06:14.203 CleanUp - Elapsed 16 usec - Info : Session does not contain modified objects in cache.
Communications 06480 006584 07:01:56.140 Elapsed 94592 usec - Container Temperature (80)
Server 07972 006860 07:06:20.281 Elapsed 516245941539 usec - No of resources in array = 0
Communications 06480 006584 07:11:56.140 Elapsed 92355 usec - Container Temperature (80)
Server 07972 006860 07:16:21.296 Elapsed 516846919543 usec - No of resources in array = 0
Communications 06480 006584 07:21:56.140 Elapsed 89978 usec - Container Temperature (80)
Server 07972 006860 07:26:22.296 CleanUpThread - Elapsed 517447899556 usec
BE 05452 009252 08:37:25.375 Elapsed 87 usec - Updating SESSION_ID
Server 04616 004744 09:24:12.437 Initialize() - Elapsed 7132 usec
Regfile.txt 包含
Container Temperature
Updating SESSION_ID
以下是我正在做的事情:
grep -E "(07:[0-9][0-9]:|08:[0-9][0-9]:).*" ABCD_ERR.LOG|grep -E -f Regfile.txt > output.txt
但我希望输出(以输出行为前缀的文件名)为
ABCD_ERR.LOG:Communications 06480 006584 07:01:56.140 Elapsed 94592 usec - Container Temperature (80)
ABCD_ERR.LOG:Communications 06480 006584 07:11:56.140 Elapsed 92355 usec - Container Temperature (80)
ABCD_ERR.LOG:Communications 06480 006584 07:21:56.140 Elapsed 89978 usec - Container Temperature (80)
ABCD_ERR.LOG: BE 05452 009252 08:37:25.375 Elapsed 87 usec - Updating SESSION_ID
有什么方法可以得到如上所示的所需输出吗? 我尝试过 /dev/null 选项,但给出错误为“grep:在标准输出上写入错误:管道正在关闭。”因为第二个 grep 的输入不是文件。 我在 Windows 7 中使用 grep
【问题讨论】: