【发布时间】:2014-09-17 13:51:29
【问题描述】:
我需要编写一些简单的脚本来分析大量日志文件,使用 grep 或 awk 的组合从每个日志中提取一个(指定)行并将其附加到一些带有名称的 result.log从中提取该行的日志文件。每个日志文件如下所示:
Detected 8 CPUs
Reading input ... done.
Setting up the scoring function ... done.
mode | affinity | dist from best mode
| (kcal/mol) | rmsd l.b.| rmsd u.b.
-----+------------+----------+----------
1 -6.8 0.000 0.000
2 -6.4 8.197 10.006
3 -5.9 1.227 2.791
4 -5.6 1.551 3.947
5 -5.2 1.061 3.325
6 -5.1 1.055 4.219
7 -4.4 2.000 3.318
8 -3.9 1.110 3.362
9 -3.8 1.460 4.123
10 -2.4 6.960 9.282
11 -2.2 1.277 4.038
12 -1.9 1.758 4.043
13 3.1 2.144 4.284
Writing output ... done.
我只需要从中提取前 5 行,包括
1 -6.8 0.000 0.000
2 -6.4 8.197 10.006
3 -5.9 1.227 2.791
4 -5.6 1.551 3.947
5 -5.2 1.061 3.325
并将其附加到 result.log 中,如下所示:
From file name1.log
1 -6.8 0.000 0.000
2 -6.4 8.197 10.006
3 -5.9 1.227 2.791
4 -5.6 1.551 3.947
5 -5.2 1.061 3.325
From file name2.log
1 -6.8 0.000 0.000
2 -6.4 8.197 10.006
3 -5.9 1.227 2.791
4 -5.6 1.551 3.947
5 -5.2 1.061 3.325
所以对于 N log 我应该在 result.log 中有 5N 个这样的行或 N 个由 5 个排名分数组成的块
脚本循环所有日志的想法=
#!/bin/bash
for log in ./*.log2; do
filename=$(basename "$log")
filenamenoextention=${filename/.log/}
#some command to extract of the line and put it to the final_results.txt
done
所以我只需要知道 grep 或 sed(从每个日志中查找 5 行)和 (mb) awk 的组合来提取选定的(例如只有 1 和 2)列
感谢您的帮助,
詹姆斯
【问题讨论】: