I need to write some simple script for analysis of big number of log files, using combination of grep or awk to extract one (specified) line from each of the log and append its to some result.log with the name of the log file from which that line have been extracted. Each of the log files looks like:
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.
I need to extract from this only first 5 lines consisted of
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
and append it to the result.log which will seems like:
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
so for N log I should to have 5N such lines or N blocks consisted of 5 some ranking scores in the result.log
the idea of the script to loop all logs =
#!/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
So I need only to know the combination of grep or sed (to find 5 lines from each log) and (mb) awk to extract selected (e.g only 1 and 2) columns
Thanks for help,
James