I am having one same file name**(report.txt)** in all sub-directories , for example I am showing the data for the file(report.txt) from 2 sub-directories as below:
report.txt in File1_D sub-directory:
Stage Family Fatals Errors Warnings Infos
----- -------- -------- -------- -------- --------
CHECK CODING 0 1 0 0
CHECK CONN 0 1 0 0
LIST CODING 0 12 0 0
LIST CONN 0 15 7 0
----- -------- -------- -------- -------- --------
Total 0 29 7 0
report.txt in File2_D sub-directory:
Stage Family Fatals Errors Warnings Infos Remaining
----- -------- -------- -------- -------- -------- ----------
CHECK CODING 0 0 1 0 0
LIST CLK 0 49 0 0 0
LIST CODING 0 3 0 0 0
LIST CONN 0 2 598 0 196
LIST SYN 0 0 100 0 126
----- -------- -------- -------- -------- -------- ----------
Total 0 54 699 0 322
In which one file(report.txt) from one sub-directory will be having six columns and in other sub-directory file(report.txt) it will be of seven columns, I need the count of the Warnings column and the output like below :
File1_D:
Total number of warnings : 7
File2_D:
Total number of warnings : 699
Here File1_D and File2_D are the sub-directories names, I tried this code as below but I am not getting the desired output:
#!/bin/bash
for d in *_D;
do
echo "$d:";
if [[ "$NF" -eq 7 ]];
then
awk '/Total/{print "Total number of warnings:" $(NF-2);exit}' "$d"/report.txt
else
awk '/Total/{print "Total number of warnings:" $(NF-1);exit}' "$d"/report.txt
fi
done