Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting and summarizing info from a log file. 2

Status
Not open for further replies.

brent01

Technical User
Jul 11, 2001
32
GB
I am a complete novice with AWK and would like to use it to extract and summarize information from a Backup Exec logfile.

I have managed the basics of extracting the raw info I want -

awk "/Job name/ { print $0 } " bex182.txt
awk "/Processed/ { print $0 } " bex182.txt
awk "/Job completion status/ { print $0} " bex182.txt

which does show all the information I want -

Job name: BNLS250a Normals
Processed 1,682,728,387 bytes in 1 hour, 33 minutes, and 13 seconds.
Processed 649,662,003 bytes in 32 minutes and 58 seconds.
Processed 97,028 bytes in 9 seconds.
Processed 111,165,992 bytes in 3 minutes and 43 seconds.
Processed 3,691,683,926 bytes in 5 hours, 51 minutes, and 29 seconds.
Job completion status: Failed

I wish to ideally format the output of the information into

columns like so -

JOB NAME BYTE COUNT STATUS
BNLS250a Normals <SUM OF ALL BYTES> FAILED

I have tried to calculate the sum of btyes processed -

awk "/Processed/ {bytes += $2} END {print bytes}" bex182.txt

which is giving me a total of 861 (seems to be adding only the figures before the first "," in number i.e. 1, 649, 97, 111, 3. How can I add the whole amount?

How can I tie this altogether to output the data, in the format I want, and with the correct calculations?

Can anybody help?

By the way - I am using AWK95 on DOS /WIndows2000 so perhaps that's why some of the syntax " etc may look a bit different.

Thanks

 

brent.awk
Code:
BEGIN{printf "%-22s%13s%10s\n","JOB NAME","BYTE COUNT","STATUS"}
/Job name/{j=substr($0,11);b=0}
/Processed/{i=$2;gsub(/,/,"",i);b+=i}
/Job completion status/{printf "%-22s%13.0f%10s\n",j,b,substr($0,24)}
awk -f brent.awk bex182.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 

Code:
BEGIN {FS = ": "; pr("JOB NAME","BYTE COUNT","STATUS")}
/^Job name/ {job=$2}
/^Processed/ {gsub(/[^0-9 ]/,""); bytes+=$0}
/^Job completion status/ {pr(job,bytes,$2)}
function pr( a,b,c ) {printf "%-23s%15s   %s\n",a,b,c}
 
Previous version neglected to reset bytes.

Code:
BEGIN {FS = ": "; pr("JOB NAME","BYTE COUNT","STATUS")}
/^Job name/ {bytes=0; job=$2}
/^Processed/ {gsub(/[^0-9 ]/,""); bytes+=$0}
/^Job completion status/ {pr(job,bytes,$2)}
function pr( a,b,c ) {printf "%-23s%15s   %s\n",a,b,c}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top