在一些work-dir中,我有几个txt文件,它们的名称采用以下格式:
1.0bar_*.log
-5.0bar_*.log
-10.0bar_*.log
...
-50.0bar_*.log
最后是一个文件,名称为:
Total_Contacts.log
我只需要循环工作目录,并将所有这些日志的容器合并到一个Final_summary.log中,从而保持上面显示的信息的顺序。
for res in ${output}/*.log; do
res_tit=$(basename "$res")
res_tit=${res_tit/.log/}
# print the name of the log firstly
printf "${res_tit}" >> ${output}/Summary_Final.log
# print the containt of the res file
# some program
# introduce space
done
请注意,在Final_summary.log的开头,我需要添加一个特殊的字符串标记,以便以以下格式指示从中获取容器的文件的名称:
That info has been taken from the 01.0bar_*.log
# here is all of the containts of the 01.0bar_*.log
That info has been taken from the -05.0bar_*.log
# here is all of the containts of the -05.0bar_*.log
That info has been taken from the -10.0bar_*.log
# here is all of the containts of the -10.0bar_*.log
****************
And finally that is the summary from Summary_Final.log
# here is all of the containts of the Summary_Final.log
发布于 2018-03-19 12:03:48
可以使用sed将文件名包括在第一列中:
for FILE in `find . -type f -name "*.log"`
do
cat $FILE | sed 's@^@\"'$FILE'\",@g' >> Total_Contacts.log
done
这样,您可以将所有文件连接在一起,并将文件名显示为第一列,结果如下所示:
01.0bar_*.log, "content of the file"
-05.0bar_*.log, "content of the file"
-10.0bar_*.log, "content of the file"
https://stackoverflow.com/questions/49302190
复制相似问题