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

Filtering Off In AWK summary 1

Status
Not open for further replies.

SteveR77

Programmer
Sep 18, 2000
813
US
I am attempting to use AWK to generate a single line summary given a date range. Currently, the values are hard coded but the intent is to pass the formatted date values. Right now I am getting the last value in the file but I am not seeing where the filtering is off in the following code.

Code:

The output currently gives me - 2014-11-05,18.8843 GB

But my expectation is that I would get 2014-11-03, 18.8843 GB which would be the total GB transferred for the applied date filter.

Thanks for your assistance with helping me get this logic worked out.


SteveR77

I.T. where a world of choas and confusion comes down to nothing but 1s and 0s.
 
Apologies.

Here is the code - awk -F":" '($1 == 2014 && $2 == 11 && $3 == 03) { tbytes+=$12} END {print $1"-" $2"-" $3"," tbytes/1000000000 " GB" }' activity_log
2014-11-05,18.8843 GB


I.T. where a world of choas and confusion comes down to nothing but 1s and 0s.
 


Like this?:

Code:
awk -F":" -v frdt='2011:11:03' '(substr($0,1,10)>=frdt) { tbytes+=$12} END {print frdt tbytes/1073741824 " GB" }' activity_log

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Thank you! I vapor locked on the substring comparison for AWK.

I.T. where a world of choas and confusion comes down to nothing but 1s and 0s.
 
The final solution:

The Command:

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


Resulting Output:

2014:11:04, 28.8526 GB

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