You are not logged in.
I'm using grep to pull some data from a log file but I can't seem to be able to get exactly what I need. What I have so far is the following:
[22:00:16] /usr/sbin/chroot [ Warning ]
What I need to do is to somehow only select the "/usr/sbin/chroot" part of what grep gives me and remove the "[22:00:16]" and the "[Warning]".
I've tried using "cut" and "sed" but I can't seem to figure it out.
Could someone point me in the right direction on what to use to be able to do this?
Thanks!
Ready yourselves, ready yourselves
Let us shine the light of Jesus in the darkest night
Ready yourselves, ready yourselves
May the powers of darkness tremble as our praises rise .... Casting Crowns-Until The Whole World Hears.
Offline
"awk" is more suited to extracting information from columnar data.
Something like:
cat mylogfile | awk '{print $1}'
Philosophy is looking for a black cat in a dark room. Metaphysics is looking for a black cat in a dark room that isn't there. Religion is looking for a black cat in a dark room that isn't there and shouting "I found it!". Science is looking for a black cat in a dark room with a flashlight.
Offline
This should be safe enough:
sed 's/^\[[^]]\+\][[:blank:]]\+//;s/[[:blank:]]\+\[[^]]\+\]$//'
"awk" is more suited to extracting information from columnar data.
Something like:cat mylogfile | awk '{print $1}'
True, but this isn't quite columnar. Also, your cat hates you right now.
Last edited by falconindy (2011-01-04 04:58:09)
Offline
This should be safe enough:
sed 's/^\[[^]]\+\][[:blank:]]\+//;s/[[:blank:]]\+\[[^]]\+\]$//'
I detect a terrible case of seditis regexposa
awk --re-interval -F'[ \n\t]{2,}' '{print $2}' $LOGFILE
as usual, the more a regexp is general, the uglier it gets.
I think a simple
awk '{print $1}' $LOGFILE
is better.
Offline
@carlocci
I think you meant
awk '{print $2}' $LOGFILE
Offline
falconindy wrote:This should be safe enough:
sed 's/^\[[^]]\+\][[:blank:]]\+//;s/[[:blank:]]\+\[[^]]\+\]$//'
I detect a terrible case of seditis regexposa
awk --re-interval -F'[ \n\t]{2,}' '{print $2}' $LOGFILE
as usual, the more a regexp is general, the uglier it gets.
I think a simple
awk '{print $1}' $LOGFILE
is better.
I'm comfortable in my seditis. Your --re-interval looks extremely gawkish, but that's definitely a handy flag to know about. Thanks.
Last edited by falconindy (2011-01-04 13:51:09)
Offline
Thanks for the help everyone.
Ready yourselves, ready yourselves
Let us shine the light of Jesus in the darkest night
Ready yourselves, ready yourselves
May the powers of darkness tremble as our praises rise .... Casting Crowns-Until The Whole World Hears.
Offline