help, using awk to get paragraph


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help, using awk to get paragraph
# 1  
Old 06-03-2008
help, using awk to get paragraph

Hi,

I'm trying to find pattern in log file. I'm using awk to search the pattern and print the paragraph. And it's not working well like I want.
The file actually is TCAP message, it has format like this :

...
...
...

*****************************************
INCOMING TCAP MESSAGE
At Thu May 22 14:41:26 2008
*****************************************
DEST ADDR: ni=0,ri=xx,pc=0xxx ssn=xx gt={noa=4,trans=0,plan=1,enc=2,addr=blabaalba}

ORIG ADDR: ni=0,ri=GT,ssn=xx gt={noa=4,trans=0,plan=1,enc=2,addr=blabab}

Received TR-BEGIN:
{
TRANSACTION PORTION:
origTransID=0x9106db37-91 06 db 37
******* INVOKE *******
Cs1InitialDP
serviceKey=XXX
callingPartyNumber=(4)NUMBER
callingPartysCategory=0xa
locationNumber=(4)number
highLayerCompatability=0x0,0x4,0x1,0x1
bearerCapability=0x0,0x0,0x0,0x10,0x3
eventTypeBCSM=2
iMSI(CAP)=XXXXX
vlrNumber(CAP)=Extension:1 NoA:1 Plan: 1 Digits:XXXX
cellIdFixedLength(CAP)=MCC:XX MNC:XX LAC:0XXX CellId:0xXXX
callReferenceNumber(CAP)=40 1c 41 34 0e 84 a6
mscAddress(CAP)=Extension:1 NoA:1 Plan: 1 Digits:XXXXX
calledPartyBCDNumber(CAP)=(0)XXXXX
**********************
}

...
...

I take Calling Party number as a pattern, and what I want is : search this full paragraph from Calling Party Number.
I use this code
Code:
awk '{RS="" } /NUMBER/' filename

but, I only get from "Received TR-BEGIN:" until "}"
How to get it full paragraph ? since it index position is unknown

Thanks
# 2  
Old 06-03-2008
Code:
awk 'BEGIN{RS="" } /NUMBER/' filename

Isn't it the full paragraph containing 'NUMBER'?
What's your definition of 'paragraph'?
What's the desired output based on the sample input you've given?
# 3  
Old 06-03-2008
hei, thanks for the response!
hm..my mistake not to describe it clearly

I have log file, for example, it's contains :

...
...

*****************************************
INCOMING TCAP MESSAGE
At Thu May 22 14:41:26 2008
*****************************************
DEST ADDR: ni=0,ri=PC,pc=0x51f ssn=146 gt={noa=4,trans=0,plan=1,enc=2,addr=0999999999}

ORIG ADDR: ni=0,ri=GT,ssn=146 gt={noa=4,trans=0,plan=1,enc=2,addr=0999999999}

Received TR-BEGIN:
{
TRANSACTION PORTION:
origTransID=0x9106db37-91 06 db 37
******* INVOKE *******
Cs1InitialDP
serviceKey=500
callingPartyNumber=(4)0899999002030
callingPartysCategory=0xa
locationNumber=(4)099999999
highLayerCompatability=0x0,0x4,0x1,0x1
bearerCapability=0x0,0x0,0x0,0x10,0x3
eventTypeBCSM=2
iMSI(CAP)=60890900250721
vlrNumber(CAP)=Extension:1 NoA:1 Plan: 1 Digits:099999999
cellIdFixedLength(CAP)=MCC:60 MNC:89 LAC:0x2710 CellId:0x795e
callReferenceNumber(CAP)=40 1c 41 34 0e 84 a6
mscAddress(CAP)=Extension:1 NoA:1 Plan: 1 Digits:099999999
calledPartyBCDNumber(CAP)=(0)08139534595494
**********************
}

*****************************************
OUTGOING TCAP MESSAGE
At Thu May 22 14:46:41 2008
*****************************************
DEST ADDR: ni=0,ri=PC,pc=0x51f ssn=146 gt={noa=4,trans=0,plan=1,enc=2,addr=0999999999}

ORIG ADDR: ni=0,ri=GT,ssn=146 gt={noa=4,trans=0,plan=1,enc=2,addr=0999999999}

Received TR-CONTINUE:
{
TRANSACTION PORTION:
origTransID=0x9106db37-91 06 db 37
destTransID=0xbb1d-00 00 bb 1d
******* INVOKE *******
Cs1ApplyChargingReport
reportData=a0 0b a0 03 81 01 01 a1 04 80 02 0b b8
CAP{
receivingSideID=1
timeIfNoTariffSwitch=3000
callActive=TRUE (default)
}
**********************
}

*****************************************
INCOMING TCAP MESSAGE
At Thu May 22 14:41:26 2008
*****************************************
DEST ADDR: ni=0,ri=PC,pc=0x51f ssn=146 gt={noa=4,trans=0,plan=1,enc=2,addr=0999999999}

ORIG ADDR: ni=0,ri=GT,ssn=146 gt={noa=4,trans=0,plan=1,enc=2,addr=0999999999}

Received TR-BEGIN:
{
TRANSACTION PORTION:
origTransID=0x9106db37-91 06 db 37
******* INVOKE *******
Cs1InitialDP
serviceKey=400
callingPartyNumber=(4)08999987059
callingPartysCategory=0xa
locationNumber=(4)0999999999
highLayerCompatability=0x0,0x4,0x1,0x1
bearerCapability=0x0,0x0,0x0,0x10,0x3
eventTypeBCSM=2
iMSI(CAP)=60890900250721
vlrNumber(CAP)=Extension:1 NoA:1 Plan: 1 Digits:0999999999
cellIdFixedLength(CAP)=MCC:60 MNC:89 LAC:0x2710 CellId:0x795e
callReferenceNumber(CAP)=40 1c 41 34 0e 84 a6
mscAddress(CAP)=Extension:1 NoA:1 Plan: 1 Digits:0999999999
calledPartyBCDNumber(CAP)=(0)0813131313131
**********************
}


*****************************************
OUTGOING TCAP MESSAGE
At Thu May 22 14:46:41 2008
*****************************************
DEST ADDR: ni=0,ri=PC,pc=0x51f ssn=146 gt={noa=4,trans=0,plan=1,enc=2,addr=0999999999}

ORIG ADDR: ni=0,ri=PC,pc=0xf1 ssn=146
Received TR-ABORT:
{
TRANSACTION PORTION:
destTransID=0xbb1d-00 00 bb 1d
pAbortCause=1
}

...
...
the message repeated again "INCOMING , OUTGOING ,..." for different callingPartyNumber. And for this file, I just want to take callingPartyNumber=(4)08999987059 's INCOMING TCAP MESSAGE.

so I use that code :
Code:
awk 'BEGIN  {RS=""} /08999987059/' filenamelog.txt

As I mention before, I only get the message from "Received TR-BEGIN:" until "}".
Is there any way to get itu full ( all message in red color) ?

Thanks

Last edited by kunimi; 06-03-2008 at 07:52 AM.. Reason: lack info
# 4  
Old 06-04-2008
I just find out this code, and it can get previous line before pattern.

Code:
awk 'BEGIN {RS=""} /08999987059/ {print x ; print};{x=$0}' filenamelog.txt

but, I need to improve it more..
can someone help me ?

Thanks.
# 5  
Old 06-04-2008
You will never learn how to use these tools unless you try to figure things out for yourself! KISS
Code:
grep -B15 -A13 08999987059 data.file

# 6  
Old 06-04-2008
Hi,

if you only want to take callingPartyNumber=(4)08999987059 's INCOMING TCAP MESSAGE

try
awk '/MESSAGE/; /callingPartyNumber/' filename.log
but need to modify it

if you want to get full message from INCOMING TCAP MESSAGE until calledPartyBSCNumber please try

awk '/INCOMING TCAP MESSAGE/,/calledPartyBCDNumber/' filename.log

perhaps like that

thanks
# 7  
Old 06-04-2008
Hi Adhit,

Thanks, but I already use that one, and it's not working like the way I want.

And danmero,

My Solaris doesn't support that grep option.

Thanks anyway.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extract paragraph that contains a value x<-30

I am using OSX. I have a multi-mol2 file (text file with coordinates and info for several molecules). An example of two molecules in the file is given below for molecule1 and molecule 2. The total file contains >50,000 molecules. I would like to extract out and write to another file only the... (2 Replies)
Discussion started by: Egy
2 Replies

2. Shell Programming and Scripting

Compare a paragraph

I know this is a challenging, its about comparing a 3 paragraph, from a whois command, i want to print what is the data that is not unique, example below is the admin phone and techphone, the rest is the same.it will print the correct and wrong # whois google.com| sed -n '/Registry Registrant... (3 Replies)
Discussion started by: kenshinhimura
3 Replies

3. Shell Programming and Scripting

How to grep paragraph?

Hi, I have A file like this: >Contig1 AAAAAAATTTTTTCCCAATATATGAT ATATATAEATATATAT >Contig2 AAAAAAATTTTTTCCCAATATATGAT ATATATAEAATTTTTAATTTTTTCCCA ATCCCAAATATATAT >Contig3 AAAAAAATTTTTTCCCAATATATGAT ATATATAEAATTTTTAATTTTTTCCCA ATCCCAAATAAATTTTTTCCCAATAT ATGATATATATAEAATTTTTAATTTTT... (3 Replies)
Discussion started by: the_simpsons
3 Replies

4. UNIX for Dummies Questions & Answers

Output text from 1st paragraph in file w/ a specific string through last paragraph of file w/ string

Hi, I'm trying to output all text from the first paragraph in a file that contains a specific string through the last paragraph in that file that contains that string. Previously, I was outputting just each paragraph with that search string with: cat in_file | nawk '{RS=""; FS="\n";... (2 Replies)
Discussion started by: carpenn
2 Replies

5. Shell Programming and Scripting

Pattern in a paragraph

Hi, I have read similar questions and I was not able to get a solution, so please help :) I have two files: 1-Pattern file contains list of patterns pattern1 pattern2 pattern3 pattern4 .... pattern# 2-input file in the format >hdhfshsdfjhpattern1xmbxmbxnmv... (4 Replies)
Discussion started by: tbakheet
4 Replies

6. UNIX for Dummies Questions & Answers

Split a paragraph

Hi, Consider the following paragraph. This is line1. This is line2, This is last line. I need the output as 4:This is last line. i.e The line after the blank line should be displayed along with line number. I am a unix begineer.Any one please help me to solve this problem (3 Replies)
Discussion started by: Sekar1
3 Replies

7. Linux

Extract a paragraph

Hi , Unix.com has been life saver for me I admit :) I am trying to extract a paragraph based on matching pattern "CREATE TABLE " from a ddl file . The paragraphs are seperated by blank line . Input file is #cat zip.20080604.sql1 CONNECT TO TST103 SET SESSION_USER OPSDM002 ... (2 Replies)
Discussion started by: capri_drm
2 Replies

8. UNIX for Dummies Questions & Answers

SED or AWK: Appending a line Identifier that changes with paragraph?

Have another question that has been eluding me all day. I have data file I'm trying to reformat so that each line is appended with an ID code, but the ID code needs to update as it searches through the file. I.e. ----Begin Original Datafile----- Condition = XXX Header Line 1 Header... (1 Reply)
Discussion started by: selkirk
1 Replies

9. Shell Programming and Scripting

extracting last paragraph from a text

Hi All, I want to extract last paragraph from a text for example aaaaa sadafsa sdfdsaf asfdsad asfdsfad asfdfsafd adfssas asdfsafdsa asfdasdfa sadfasdsaf i need the last paragraph how to do it using linux commands (1 Reply)
Discussion started by: uvrakesh
1 Replies

10. Shell Programming and Scripting

Bold the paragraph

Hi, I have a file with multiple paragraph. I want to look for some word and make that paragraph bold. How can I do that? Thanks, Karthik (3 Replies)
Discussion started by: caprikar
3 Replies
Login or Register to Ask a Question