Computing.Net > Forums > Unix > Help with AWK to extract text block

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Help with AWK to extract text block

Reply to Message Icon

Name: mjdunn
Date: December 16, 2007 at 18:59:05 Pacific
OS: Solaris
CPU/Ram: SunSparc / 4096
Product: Sun Apache
Comment:

Hi there
I am hoping you could help me with a script that would search for a word and extract the block of text containing it.
This is a log file containing multiple messages.
I would like to first search for a keyword, ("bwSipRequestTimeOutReceived")and then extract the lines of text containing it. Each log is seperated by a blank line.See below as an example of lines of text of the message

any help with awk or similar command to acheive this would be greatly appreciated.
Thankyou very much

3234049,1197578062818,1,0,false,
"bwSipRequestTimeOutReceived",
"as1",
"Application Server",
"SIP",
"SIP respond 408 Request Timeout received.
Response Message:
SIP/2.0 408 Request Timeout
Via:SIP/2.0/UDP 218.101.55.1:5060;received=218.101.55.1;branch=z9hG4bK-BroadWorks.218.101.55.1-218.101.55.201V5060-0-714830972-479130644-1197578053878-
Call-ID:BW093413878141207-1215374075@218.101.55.1
From:<sip:+xxxxxxx@218.101.55.1;user=phone>;tag=479130644-1197578053878-
To:<sip:011691yyyyyyyyy@csps.softswitch.ddddddd.net:5060;user=phone>;tag=2891-587c
CSeq:714830972 INVITE
Content-Length:0




Sponsored Link
Ads by Google

Response Number 1
Name: Ankit Jain
Date: December 16, 2007 at 20:07:30 Pacific
Reply:

i think this may work, but will need some manipulation.

FILE="path of log file"
SEARCH="\"bwSipRequestTimeOutReceived\""
cat $FILE | \
while read line
do
index1="`awk -v a="$line" -v b="$SEARCH" 'BEGIN{print index(a,b)}'` "
if [ index1 -ne 0 ] ;
then
echo $line
fi
done


Jain Sahab


0

Response Number 2
Name: FishMonger
Date: December 17, 2007 at 10:50:21 Pacific
Reply:


perl -00 -ne 'print if /bwSipRequestTimeOutReceived/' file.log


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Help with AWK to extract text block

awk script to extract text www.computing.net/answers/unix/awk-script-to-extract-text/5899.html

Help with awk/sed www.computing.net/answers/unix/help-with-awksed/6548.html

Printing with AWK Utility www.computing.net/answers/unix/printing-with-awk-utility/6219.html