while read line
do
awk '
/ERROR/ {
print
for (i=1; i<=10; i++) {
getline; print
}
exit
}
' $line
echo $line
done < logfiles.csv >> results.csv
使用上面的代码,我在results.csv文件中得到如下输出
1.log
ERROR
2.log
ERROR
但想要下面的输出
1.log ERROR
2.log ERROR
我的logfile.csv包含如下信息
1.log
2.log
答案 0 :(得分:1)
好吧,我认为:
ERROR
模式,如果包含,则必须在行中打印文件名和"ERROR"
在Python中可以很直接:
with open("logfiles.csv") as files, open("result.csv", "w") as fdout:
for filename in files: # read input file line by line
filename = filename.strip() # strip end of line
with open(filename) as fd: # open each log file
for line in fd:
if 'ERROR' in line: # search the pattern ERROR in any line
print(filename, 'ERROR', file=fdout) # message if found
break # and stop processing that log