INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Filtering Off In AWK summary

Filtering Off In AWK summary

(OP)
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 --> activity_log

 

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.

RE: Filtering Off In AWK summary

(OP)
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.

RE: Filtering Off In AWK summary



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

RE: Filtering Off In AWK summary

(OP)
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.

RE: Filtering Off In AWK summary

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close