Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
05-31-2012, 10:10 AM
|
#1
|
|
Member
Registered: May 2007
Posts: 100
Rep:
|
using awk on a file
Hi
I have the following jboss_gc.log and i want to convert to csv file .
Any ideas why the awk below is not paring the file correctly ?
gc.log file
Code:
3.811: [GC 129152K->9220K(261184K), 0.0536640 secs]
5.971: [GC 138372K->18688K(261184K), 0.0488410 secs]
7.490: [GC 147840K->28092K(261184K), 0.0252540 secs]
8.291: [GC 157244K->28483K(261184K), 0.0025680 secs]
8.797: [GC 157635K->28655K(261184K), 0.0012670 secs]
9.326: [GC 157807K->29009K(261184K), 0.0016340 secs]
10.062: [GC 158161K->32141K(261184K), 0.0152050 secs]
10.796: [GC 161293K->34653K(261184K), 0.0236380 secs]
17.251: [GC 163805K->39059K(261184K), 0.0163560 secs]
17.879: [GC 168211K->41905K(261184K), 0.0119190 secs]
18.589: [GC 171057K->46506K(261184K), 0.0186890 secs]
20.031: [GC 175658K->53395K(261184K), 0.0597250 secs]
20.091: [GC 55959K(261184K), 0.0096890 secs]
20.414: [GC 182547K->55929K(261184K), 0.0236070 secs]
20.726: [Full GC 120483K->55851K(261184K), 0.3002330 secs]
21.070: [GC 58433K(261184K), 0.0023200 secs]
21.772: [GC 185003K->65093K(261184K), 0.0550760 secs]
22.726: [GC 143416K(261184K), 0.0396670 secs]
23.196: [Full GC 193833K->68977K(261184K), 0.0352740 secs]
23.232: [GC 71357K(261184K), 0.0022760 secs]
24.399: [GC 198129K->70638K(261184K), 0.0158770 secs]
Code:
GC_LOG=$JBOSS"/jboss_gc.log"
grep "Full GC" $GC_LOG | awk '{print $8}' | awk 'BEGIN {FS="K->"};{print $1""$2}' | awk 'BEGIN {FS="K"};{print $1}'| awk '{print $1","$2}'>>/tmp/out.csv
|
|
|
|
05-31-2012, 10:23 AM
|
#2
|
|
Moderator
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.4 OpenSuSE 12.2
Posts: 9,897
|
None of the lines you posted has 8 fields, so the first
prints nothing. I would not use a similar chain of grep and multiple awk processes. You can do it all with a single call to awk. Please, post an example of the desired output, based on the input above, and we could give some better advice.
|
|
|
|
05-31-2012, 10:51 AM
|
#3
|
|
Member
Registered: May 2007
Posts: 100
Original Poster
Rep:
|
This is the file
Code:
64519.455: [Full GC 784436K->538165K(784448K), 12.7143926 secs]
164534.199: [GC 547731K(784448K), 0.2120279 secs]
164547.339: [GC 583344K(784448K), 0.3589552 secs]
164551.387: [GC 591125K(784448K), 0.5363759 secs]
164558.084: [GC 605668K(784448K), 0.5198986 secs]
164561.962: [GC 614448K(784448K), 0.6760577 secs]
164568.773: [GC 628705K(784448K), 0.6676036 secs]
164571.995: [GC 636129K(784448K), 0.8861083 secs]
164579.121: [GC 650744K(784448K), 0.8984039 secs]
164583.355: [GC 660185K(784448K), 1.0209936 secs]
164590.619: [GC 675616K(784448K), 1.0320532 secs]
164594.169: [GC 681971K(784448K), 1.1254689 secs]
164601.674: [GC 706273K(784448K), 1.0027303 secs]
164605.759: [GC 711446K(784448K), 1.3872742 secs]
164613.461: [GC 729877K(784448K), 1.3498643 secs]
164617.313: [GC 736181K(784448K), 1.6499854 secs]
164625.248: [GC 753574K(784448K), 1.5982310 secs]
164629.200: [GC 757053K(784448K), 1.5155503 secs]
164637.251: [GC 776190K(784448K), 1.6940726 secs]
164641.190: [GC 780727K(784448K), 1.9722320 secs]
164649.339: [Full GC 784440K->539326K(784448K), 14.2416926 secs]
so i want to take the value 784448K, 14.2416926 secs and graph this
|
|
|
|
05-31-2012, 11:28 AM
|
#4
|
|
Senior Member
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 2,805
|
avoid writing such chains: grep | awk | awk | awk | awk
You need only one awk to implement this:
Code:
awk ' BEGIN { FS="[- ,K>()]*" } /Full GC/ { print $6 "," $7 } ' >> /tmp/out.csv
__________________________________
Happy with solution ... mark as SOLVED
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
Last edited by pan64; 05-31-2012 at 11:31 AM.
Reason: script corrected
|
|
|
|
06-01-2012, 03:26 AM
|
#5
|
|
Member
Registered: May 2007
Posts: 100
Original Poster
Rep:
|
This still gives me nothing back
Any ideas why ?
Code:
grep "Full GC" $GC_LOG | awk ' BEGIN { FS="[- ,K>()]*" } /Full GC/ { print $6 "," $7 } ' >> /tmp/out.csv
|
|
|
|
06-01-2012, 03:33 AM
|
#6
|
|
Senior Member
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 2,805
|
Code:
awk ' BEGIN { FS="[- ,K>()]*" } /Full GC/ { print $6 "," $7 } ' $GC_LOG >> /tmp/out.csv
would be better, it worked for me. probably you can remove >>/tmp/out.csv and test, what can you see?
|
|
|
|
06-01-2012, 03:55 AM
|
#7
|
|
Member
Registered: May 2007
Posts: 100
Original Poster
Rep:
|
Thanks that worked now if i also want to check if there was more than one Full GC string in the file i will throw an error
How could i handle that ?
|
|
|
|
06-01-2012, 04:11 AM
|
#8
|
|
Senior Member
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 2,805
|
Code:
awk ' BEGIN { FS="[- ,K>()]*"; counter=0 } /Full GC/ { if ( counter++ ) { exit 1 } else print $6 "," $7 } ' $GC_LOG >> /tmp/out.csv
you can modify { exit 1 } to print a message also if you want to do so:
{ print "THIS IS AN ERROR" > "/dev/stderr"; exit 1 }
_____________________________________
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.
Happy with solution ... mark as SOLVED
(located in the "thread tools")
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:24 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|