![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| split large file based on field criteria | asriva | Shell Programming and Scripting | 6 | 06-22-2009 10:41 AM |
| Sort alpha on 1st field, numerical on 2nd field (sci notation) | FrancoisCN | Shell Programming and Scripting | 1 | 06-12-2009 10:45 AM |
| Find top N values for field X based on field Y's value | FrancoisCN | Shell Programming and Scripting | 1 | 05-29-2009 09:57 AM |
| Split file based on field | s_adu | Shell Programming and Scripting | 6 | 05-07-2009 02:08 PM |
| add lines automatically based on a field on another file | melanie_pfefer | Shell Programming and Scripting | 0 | 07-24-2008 02:59 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
awk - Summing a field based on another field
So, I need to do some summing. I have an Apache log file with the following as a typical line:
Code:
127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 Code:
awk '{print substr($4,2,17)}' logfile
Code:
awk 'substr($4,2,17) == "10/Oct/2000:13:55" && $9 ~ /^[0-9]$*/ && $10 ~ /^[0-9]$*/ {sum += $10}' logfile
|
|
||||
|
Oh, wow... that's awesome. Thank you very much. A quick followup question of the sort that I usually hate...
If I read that correctly, it doesn't even require that the log entries be in date/time order. Is that so? |
|
||||
|
Quote:
Again, many thanks. This is a fantastic time saver. |
|
||||
|
Hi vgersh99,
I'm just going through this post and having trouble understanding the code. Could you please explain the rindex function for me? I'm still learning.. Quote:
Code:
idx=substr($4, 2, 17) |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|