Hi , I need to grep "swltId" line and line 3 & 4 after "NumEULUsersPerCell" string line in hundred over file below are the example file
<SWLT customerId="944267" productType="WRAN" swltId="URM321">
<generalInfo>
<generated>2009-09-21T16:30:04</generated>
<issuer>Ericsson AB</issuer>
</generalInfo>
<fingerprint method="1" print="X911561304">
<featureKey id="CXC4030569">
<description>FAJ121148; RabCombination069</description>
<start>2009-09-21</start>
<description>FAJ1210450; FAJ1210451; FAJ1210452; NumEULUsersPerCell</description>
<start>2009-09-21</start>
<noStop/>
<capacity>32</capacity>
<hardLimit>32</hardLimit>the output should be as below :-
swltId="URM321"> NumEULUsersPerCell</description> <capacity>32 <hardLimit>32
Your advice and support in this regards are highly appreciated .
Thanks ,
Roy
a way ..... #!/bin/ksh awk ' BEGIN { FS="<" } # setting FS to < parses the last 2 lines correctly { if($0 ~ /swltId/) { ind=index($0, "swltId") # assume swltId string is at the end of the record printf("%s", substr($0, ind, length($0) )) } if($0 ~ /NumEULUsersPerCell/) { ind=index($0, "NumEULUsersPerCell") printf("%s", substr($0, ind, length($0) )) # skip 3 lines getline getline getline printf("%s%s", FS, $2) getline printf("%s%s", FS, $2) } } ' datafile.txt
Hi Nails , Thanks for your reply .. the script doesn't work correctly as I want ..
1) The output not include with swltId="xxxx"
2) The output shows only for one xml ..
3) I want the script to extract the information from hundreds over xml files from directory .
emogthu2@santuas4n> ls -l
total 100
-rw-r--r-- 1 emogthu2 nms 16275 Jan 28 04:38 X911561304_270111_2132.xml
-rw-r--r-- 1 emogthu2 nms 16900 Jan 28 03: X911562362_110126_003817.xml
-rwxrwxrwx 1 emogthu2 nms 508 Jan 31 09:42 lic.ksh
-rw-r--r-- 1 emogthu2 nms 0 Jan 31 10:02 license.txt
-rw-r--r-- 1 emogthu2 nms 16275 Jan 28 04:02 licensekeys.xml
emogthu2@santuas4n>
emogthu2@santuas4n>
emogthu2@santuas4n>
emogthu2@santuas4n> cat *.xml | ./lic.ksh
<capacity>32<hardLimit>32emogthu2@santuas4n> ---- > Here is the resultThanks ,
Samroy
>> 1) The output not include with swltId="xxxx" I am not having a problem. In my example script, this is the output from the script which, I believe is what you asked for:
swltId="URM321">NumEULUsersPerCell</description><capacity>32<hardLimit>32
Remember that awk is case sensitive, so swltId is different from swlid.
>> 3) I want the script to extract the information from hundreds over xml files from directory .
First, change the script to change to the directory where your xml files reside:
cd <your directory>
Second, you don't say, so I am assuming that the output goes to one file. Place a for loop around your awk script asking for all files ending in xml:
rm -f outputfile
for file in *.xml
do# place your awk script here.
# echo a line so there is a carriage return between output
echo
done >> outputfileAll you have to do is change the input file name of the awk script. In my example, change
} ' datafile.txt
to
} ' "$file"
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |