【发布时间】:2017-11-01 02:39:40
【问题描述】:
您好,我这里有一个清单:
list_1.txt
Alpha
Bravo
Charlie
以及目录中具有以下文件名和内容的文件:
Alpha_123.log
This is a sample line in the file
error_log "This is error1 in file"
This is another sample line in the file
This is another sample line in the file
This is another sample line in the file
error_log "This is error2 in file"
This is another sample line in the file
This is another sample line in the file
error_log "This is error3 in file"
This is another sample line in the file
This is another sample line in the file
Alpha_123.sh
This is a sample line in the file
This is another sample line in the file
This is another sample line in the file
error_log "This is errorA in file"
This is another sample line in the file
This is another sample line in the file
This is another sample line in the file
This is another sample line in the file
error_log "This is errorB in file"
This is another sample line in the file
This is another sample line in the file
error_log "This is errorC in file"
This is another sample line in the file
Bravo.log
Charlie.log
Bravo.log 和 Charlie.log 的内容与 Alpha.log 类似
我想要这样的输出:
Alpha|"This is error1 in file"
Alpha|"This is error2 in file"
Alpha|"This is error3 in file"
Alpha|"This is errorA in file"
Alpha|"This is errorB in file"
Alpha|"This is errorC in file"
非常感谢任何输入。谢谢!
所以基本上,我想首先在list_1.txt中找到名称包含字符串模式的文件,然后找到错误消息并使用|输出
【问题讨论】:
-
您可以从格式化问题开始 - stackoverflow.com/editing-help 并添加您尝试解决此问题的内容..
-
您的问题不清楚。更新您的描述
-
你想做什么
-
基本上,我想在list_1.txt中找到带有字符串模式的日志文件。然后在这些文件中搜索包含“error_log”的行,并输出包含 list_1.txt 中的字符串模式和包含用管道分隔的“error_log”的行。
-
我有这个但是这个:cat list_1.txt | awk '{打印 $1}' |同时读取 x ;回声 $x"|"
ls log_directory | grep $x | xargs -i grep error_log log_directory {} | egrep -v; done 但是输出是这样的: Alpha|error_log "This is error1 in file" error_log "This is error2 in file" error_log "This is error3 in file" 我想要的是这样的:Alpha|"This is error1 in file" Alpha |"这是文件中的错误 2"Alpha|"这是文件中的错误 3"
标签: unix awk sed grep text-processing