XML parsing using nawk help needed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting XML parsing using nawk help needed
# 1  
Old 05-08-2012
XML parsing using nawk help needed

i need one help, below is one more xml file with diff pattern i tried it but dint get it , iam sure its a peice of cake for you guys.



Code:
<xn:MeContext id="LSVLKY001">
 <xn:ManagedElement id="1">                         
<un:RncFunction id="1">                             
<un:UtranCell id="KYLSU17A">                                 
<un:attributes>                                     
<un:localCellId>10071</un:localCellId> 
 <un:uarfcnUl>862</un:uarfcnUl>                                     
<un:uarfcnDl>1087</un:uarfcnDl>
 <unprimaryScramblingCode>361</unprimaryScramblingCode>
 <unprimaryCpichPower>315</unprimaryCpichPower> 
<un:maximumTransmissionPower>416</un:maximumTransmissionPower> 
 <unprimarySchPower>-18</unprimarySchPower> 
<un:cId>10071</un:cId>                                     
<un:secondarySchPower>-35</un:secondarySchPower>
 <un:bchPower>-31</un:bchPower> 
  <un:lac>15913</un:lac>                                     
<un:rac>13</un:rac> 
<un:sac>10071</un:sac>                 
</un:attributes>                                 
<xn:VsDataContainer id="KYLSU17A">                                     
<xn:attributes> 
<es:cellReserved>1</es:cellReserved> 
<es:administrativeState>1</es:administrativeState>
 </xn:attributes>
 </xn:VsDataContainer>
 </un:UtranCell>             
</un:RncFunction>
 </xn:ManagedElement>
 </xn:MeContext>

The xml file has the following lines in the file
There are n number of Mecontext id loops
there are y number of utrancell id loops in each Mecontext loop.
I deleted some unwanted data. i want the output to be in the following format



Code:
RNC   UtranCell   cId   uarfcnUl   uarfcnDl   primaryScramblingCode   primaryCpichPower   maximumTransmissionPower   primarySchPower   secondarySchPower   bchPower   lac   rac   sac   cellReserved   administrativeState                              
LSVLKY53RNC01   KYLSUTOY6552C   65523   862   1087   3   337   446   -18   -35   -31   15913   13   65523   1   1        
LSVLKY53RNC01   KYLSUTOY6552B   65524   862   1087   3   337   446   -18   -35   -31   15913   13   65523   1   1        
LSVLKY53RNC01 TNLSUTOY2018T 20183   862   1087   3   337   446   -18   -35   -31   15913   13   65523   1   1        
SNJNLIDCR0R03   PRSJUTOY0051Y   51   812   1037   246   337   446   -18   -35   -31   51799   255   51   1   1 
SNJNLIDCR0R03   PRSJUTOY0051X   51   812   1037   246   337   446   -18   -35   -31   51799   255   51   1   1

# 2  
Old 05-08-2012
just an idea...of you really need to be rough..

Code:
BEGIN { print "RNC   UtranCell   cId   uarfcnUl   uarfcnDl   primaryScramblingCode   primaryCpichPower   maximumTransmissionPower   primarySchPower   secondarySchPower   bchPower   lac   rac   sac   cellReserved   administrativeState";print; )

/MeContext/ ' { a=gsub(/[^[:alnum:]]/, " ", $0); RNC=a[4]; }
/UtranCell/ {  a=gsub(/[^[:alnum:]]/, " ", $0); UTRANCELL=a[4]; }
/uarfcnUl/  { a=gsub(/[^[:alnum:]]/, " ", $0);  UARFCNUL=a[3]; }
/uarfcnDl/ { a=gsub(/[^[:alnum:]]/, " ", $0);  UARFCNDL=a[3]; }
/unprimaryScramblingCode/ { a=gsub(/[^[:alnum:]]/, " ", $0);  PRIMARYSCRAMBLINGCODE=a[2]; }
/unprimaryCpichPower/ { a=gsub(/[^[:alnum:]]/, " ", $0); PRIMARYCIPHERPOWER=a[2];}
/maximumTransmissionPower/ {a=gsub(/[^[:alnum:]]/, " ", $0); MAXTRXNPOWER=a[3]; }
/unprimarySchPower/ { a=gsub(/[^[:alnum:]]/, " ", $0);  PRIMARYSCHPOWER=a[2] ;}
/secondarySchPower/ { a=gsub(/[^[:alnum:]]/, " ", $0); SCNDRYSCHPOWER=a[3]; }
/bchPower/ { a=gsub(/[^[:alnum:]]/, " ", $0); BCHPOWER=a[3]; 
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s", RNC, UTRANCELL, UARFCNUL,UARFCNDL, PRIMARYSCRAMBLINGCODE, PRIMARYCIPHERPOWER, MAXTRXNPOWER, PRIMARYSCHPOWER, SCNDRYSCHPOWER, BCHPOWER ); }' input.xml

# 3  
Old 05-10-2012
Hi busyboy,
Can you please explain how to use the script that you mentioned.thanks in advance.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

XML parsing

i have xml output in below format... <AlertsResponse> <Alert id="11216" name="fgdfg"> <AlertActionLog timestamp="1356521629778" user="admin" detail="Recovery Alert"/> </Alert> <Alert id="11215" name="gdfg <AlertActionLog timestamp="1356430119840" user=""... (12 Replies)
Discussion started by: vivek d r
12 Replies

2. Shell Programming and Scripting

XML: parsing of the Google contacts XML file

I am trying to parse the XML Google contact file using tools like xmllint and I even dived into the XSL Style Sheets using xsltproc but I get nowhere. I can not supply any sample file as it contains private data but you can download your own contacts using this script: #!/bin/sh # imports... (9 Replies)
Discussion started by: ripat
9 Replies

3. Shell Programming and Scripting

Need help parsing data with sed and/or nawk

Good day all. I have the following entries of data in a file in a column, however, I need this data written on a single line with several parameters in a different order. Current format: Treatment ,parmeter1=value ,parmeter2=value ,parmeter3=value ,parmeter4=value... (7 Replies)
Discussion started by: BRH
7 Replies

4. Shell Programming and Scripting

Help needed for parsing large XML with awk.

My XML structure looks like: <?xml version="1.0" encoding="UTF-8"?> <SearchRepository> <SearchItems> <SearchItem> ... </SearchItem> <SearchItem> ... ... (1 Reply)
Discussion started by: jasonjustice
1 Replies

5. Shell Programming and Scripting

Help in parsing xml file (sed/nawk)

I have a large xml file as shown below: <input> <blah> <blah> <atr="blah blah value = ""> <blah> <blah> </input> ..2nd chunk... ..3rd chunk... ...4th chunk... All lines between <input> and </input> is one 'order' and this 'order' is repeated... (14 Replies)
Discussion started by: shekhar2010us
14 Replies

6. Shell Programming and Scripting

nawk help needed

HI, i have input files.it have comma separated records but with some leading and trailing spaces.names of input files,(you may use any dummy comma delimited input records) ls /u01 eG_20100805_0000504_110208 eG_20100805_0000505_121154 eG_20100805_0000506_130233 i need single output... (1 Reply)
Discussion started by: malikshahid85
1 Replies

7. Shell Programming and Scripting

how to parse the file in xml format using awk/nawk

Hi All, I have an xml file with the below format. <a>111</a><b>222</b><c>333<c><d><e>123</e><f>234</f><d><e>456</e><f>789</f> output needed is 111,222,333,123,234 111,222,333,456,789 nawk 'BEGIN{FS="<|>"} {print a,b,c,e,f a="" ... (7 Replies)
Discussion started by: natalie23
7 Replies

8. Shell Programming and Scripting

parsing(xml) using nawk/awk

Hi , I have an xml format as shown below: <Info> <last name="sean" first name="john"/> <period="5" time="11"/> <test value="1",test2 value="2",test3 value="3",test4 value="5"> <old> <value1>1</value1> <value2>2</value2> </old> <new> <value1>4</value1> <value2>3</value2> </new>... (1 Reply)
Discussion started by: natalie23
1 Replies

9. Shell Programming and Scripting

nawk help needed

guys, i need help the file $ cat file1 1 2 3 4 5 6 7 8 9 my script $ cat nawk1 #!/bin/sh echo "from column? :\c" read c1 echo "until column? :\c" read c2 cat file1 | nawk `{ print $c1, $c2 }` result $ ./nawk1 (3 Replies)
Discussion started by: ajiep
3 Replies

10. Shell Programming and Scripting

Parsing xml using awk - more help needed

As per another thread - https://www.unix.com/shell-programming-scripting/81027-how-can-i-parse-xml-file-2.html I am using the following to extract the Subaccid and RecAccTotal from the xm file below awk -v v=SubaccId -F'' '$2==v{s=$3;getline;a+=$3}END {for (i in a)print v,i,a}' file Can... (6 Replies)
Discussion started by: frustrated1
6 Replies
Login or Register to Ask a Question