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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unexpected Sum with AWK 1

Status
Not open for further replies.

SteveR77

Programmer
Sep 18, 2000
813
0
0
US
I have the following code -

#!/bin/bash
#

while read line
do
awk -F":" -v frdt=$(date --date="$line" +%Y:%m:%d) '(substr($0,1,10)==frdt) { count++} { tbytes+=$12} END {print frdt ", " tbytes/1073741824 ", " count }' /usr/roc/om/server/adm/activity_log

done < DATES

I expected the tbytes value to change based on the date and the amount of data transferred for the given date but the value remains the same.

What am I missing?

Thank you in advance for your help.

SteveR



I.T. where a world of choas and confusion comes down to nothing but 1s and 0s.
 
Replace this:
(substr($0,1,10)==frdt) { count++} { tbytes+=$12}
with this:
(substr($0,1,10)==frdt) { count++; tbytes+=$12}

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

Thank you very much! I had been looking at this too long and forgot about the semi colon to group by the value I needed.

Thank you once again and make it a great day.

SteveR

I.T. where a world of choas and confusion comes down to nothing but 1s and 0s.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top