![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Parse for errors shell script | bubba112557 | Shell Programming and Scripting | 2 | 04-02-2009 11:25 AM |
| How to: Parse text string into variables using Korn shell | shew01 | Shell Programming and Scripting | 7 | 05-23-2008 10:01 AM |
| Parse String in XML file | racbern | Shell Programming and Scripting | 4 | 12-19-2007 12:26 PM |
| Search and Parse string from inside a File | SSims | UNIX for Dummies Questions & Answers | 2 | 11-08-2007 03:50 PM |
| How to parse config variables from external file to shell script | pradsh | Shell Programming and Scripting | 2 | 07-09-2007 02:21 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi! I'm just new here and don't know much about shell scripting. I just want to ask for help in creating a shell script that will parse a string or value of the status in the xml file. Please sample xml file below. Can you please help me create a simple script to get the value of status? Also it would be better if I can get the values of each parameter from the xml file. I really need it asap. Hope someone can help me. Thanks!
<?xml version="1.0"?><message><cdr version="1.0"><appid>testbed</appid><threadid>6</threadid><origin>node1</origin><date>20071009 </date><time>12:45:36</time><chdate>20071009</chdate><chtime>12:45:43</chtime><status>201</status><type>103</type><calling>644</call ing><cparty>xxxxxxx</cparty><accnum>xxxxxx</accnum><debirate1>0.0</debirate1><cos>-1</cos><strtbal>0.0</strtbal><freesms>0</ freesms><tuc>0</tuc><fandftype></fandftype></cdr></message> |
|
|||||
|
Quote:
nawk -f ay.awk ay.xml ay.awk: Code:
BEGIN {
FS="[><]"
}
{
for(i=8; i<=NF; i+=2) {
if ( $i ~ /^[/]/ ) continue
printf("name->[%s] value->[%s]\n", $i, $(i+1))
}
}
|
|
||||
|
Parse a string in XML file using shell script
Thanks for the reply. I tried sed but I got error sed: command garbled: s/\(<status>\)\(.*\)\(</status>\)/\2/. I just need to get the values of all the status from the xml file like <status>201</status> because it generates different values. The xml file is huge,filesize is approx 5Mb. Please see sample portion of xml file below which is just repeated with different values. I'm really having problem getting the values of status because it's a huge file and the format is not organized sometimes in a line you can have several occurance of status. I can't change the format since it's a cdr. It would be better if I will also get the values of other parameters like appid, threadid, date, chdate, etc. I do hope you were able to understand me. Thanks again!
<?xml version="1.0"?><message><cdr version="1.0"><appid>testbed</appid><threadid>6</threadid><origin>node1</origin><date>20071009 </date><time>12:45:36</time><chdate>20071009</chdate><chtime>12:45:43</chtime><status>201</status><type>103</type><calling>644</call ing><cparty>xxxxxxx</cparty><accnum>xxxxxx</accnum><debirate1>0.0</debirate1><cos>-1</cos><strtbal>0.0</strtbal><freesms>0</ freesms><tuc>0</tuc><fandftype></fandftype></cdr></message> |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|