![]() |
|
|
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 |
| Sed/Awk Help needed | liketheshell | Shell Programming and Scripting | 1 | 07-14-2008 02:43 AM |
| help with sed needed | arushunter | Shell Programming and Scripting | 8 | 06-25-2007 12:10 PM |
| Scp Help Needed !!!! | scooter17 | UNIX for Dummies Questions & Answers | 3 | 09-20-2006 01:50 PM |
| Sed help needed | stevefox | Shell Programming and Scripting | 5 | 12-05-2005 01:44 AM |
| SED help needed | stevefox | Shell Programming and Scripting | 8 | 11-16-2005 09:21 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Awk help needed
I have a log file monitor script that checks through a log file for a string. I use awk to search the log file, starting at the last checked line, for the specified string and then output the count and the last row number checked. The part of the script that does all the work is here: Code:
set -- $(awk -v lines=$lineslastrun -v pattern="$searchpattern" '
BEGIN { count=0 }
NR > lines && $0 ~ pattern { count++ }
END { print NR; print count }
' $logfile)
totallines=$1
matches=$2
This particular log is a java app server log and we're looking for the occurance of "Full GC". Now, they want to only count the Full GC if the amount of recovered space is less than 100000. This is what the total output of a Full GC looks like in the log: Code:
844174.631: [Full GC 844174.631: [ParNew Desired survivor size 13402112 bytes, new threshold 15 (max 15) - age 1: 1365536 bytes, 1365536 total - age 2: 122888 bytes, 1488424 total - age 3: 225712 bytes, 1714136 total - age 4: 320592 bytes, 2034728 total - age 5: 8368 bytes, 2043096 total - age 6: 483952 bytes, 2527048 total - age 7: 28256 bytes, 2555304 total - age 8: 63768 bytes, 2619072 total - age 9: 106576 bytes, 2725648 total - age 10: 11960 bytes, 2737608 total - age 11: 344 bytes, 2737952 total - age 12: 111824 bytes, 2849776 total - age 13: 105072 bytes, 2954848 total - age 14: 189000 bytes, 3143848 total - age 15: 1544 bytes, 3145392 total : 212035K->3096K(235968K), 0.0180000 secs] 2079826K->1871065K(2333120K), 0.0181290 secs] I have bolded the 2 numbers I need to calculate. If the first number minus the second number is less than 100000 then I want to advance the count. I'm stuck. I've created a mock log and messed around a bit and only came up with this: Code:
awk '/Full GC/,/^:/ {if (/^:/) print $5}' testawk.data | awk -F \( '{ print $1 }' | tr -d '\-\>' | tr 'K' ' ' | awk '{if ($1-$2<100000) print}'
I can figure out how to get that into my set command above and get it to output the count. I can't figure out how I'll output the last line number of the log that was checked. I'm hoping someone can take the time to show me how to do this properly. Thanks |
|
||||
|
Thanks for the nudge in the right direction. First off, I didn't know I could perform the calculation without removing the "K" from each number. That certainly saved some steps. Besides that, your rewrite allows me to fit it all in a single awk which makes outputting the number of lines easy. Here's what I came up with: Code:
awk 'BEGIN { count=0 } NR > 10 && /Full GC/,/^:/ {if (/^:/) split($5, a, "[->(]"); else next; if (a[1]-a[3]<100000) count++} END { print NR; print count }' testawk.data
The 'NR > 10' will actually be 'NR > lines' once I incorporate it into the script. You can see it in my first post. This allows me to skip over log file entries checked in previous runs of the script. Thanks again ---------- Post updated 10-28-09 at 04:07 PM ---------- Previous update was 10-27-09 at 06:25 PM ---------- All is working well except I can't seem to pass the search string to awk. Here's the snippit: Code:
set -- $(awk -v lines=$lineslastrun -v pattern="$searchpattern" '
BEGIN { count=0 }
NR > lines && /Full GC/,/^:/ {if (/^:/) split($5, a, "[->(]"); else next; if (a[1]-a[3]<100000) count++}
END { print NR; print count }
' $logfile)
totallines=$1
matches=$2
I would like to change "Full GC" to "pattern" so I can pass the string as a variable to awk. Unfortunately it only works if I put in as it is above. I have tried many versions of single and double quotes: Code:
NR > lines && /pattern/,/^:/ {if (/^:/) split($5, a, "[->(]"); else next; if (a[1]-a[3]<100000) count++}
NR > lines && "/pattern/",/^:/ {if (/^:/) split($5, a, "[->(]"); else next; if (a[1]-a[3]<100000) count++}
NR > lines && /"pattern"/,/^:/ {if (/^:/) split($5, a, "[->(]"); else next; if (a[1]-a[3]<100000) count++}
Plus many more. None worked. Any suggestions? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|