![]() |
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 |
| Exception Handling | bertpereira | Shell Programming and Scripting | 5 | 01-14-2009 09:28 PM |
| Sorting a column in this scenario | krishnan_6015@y | Shell Programming and Scripting | 1 | 11-27-2007 09:34 AM |
| Weird scenario with Awk | Khoomfire | UNIX for Advanced & Expert Users | 4 | 10-29-2007 12:25 AM |
| Signal Handling | themezzaman | High Level Programming | 3 | 07-12-2006 11:05 PM |
| help in handling loops | borncrazy | Shell Programming and Scripting | 1 | 08-02-2004 06:24 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Handling of the various XML syntax scenario
Hi hackers,
I would like to parse the value of one XML tag (e.g. <TAG>). Following is the script that I have written. awk -F"[<>]" '/<TAG>/,/<\/TAG>/ { if ( NF == 1 ) { sub(/^[ \t]*/,"", $1) print $1 } } Above ascipt works fine for the following XML tag syntax. i.e. prints "Hi" <TAG> Hi </TAG> But the script is not able to handle the following cases 1. <TAG>Hi</TAG> 2. <TAG>Hi </TAG> 3. <TAG> Hi</TAG> Could someone help me out to enhance the script so that script can handle the above 3 cases also. TIA, Viki |
|
||||
|
Thanks for quick response.
The suggested script is able to parse the XML tag. But suggested script prints all the lines (except XML tags) present in the file. My requirement is to extract & print only the value of XML tag from the file. For example, If the file contains the following <FILE> www.unix.com Enhanced Mode <TAG> Hi </TAG> Enhanced Mode </FILE> I need to print only "Hi". TIA, Viki |
|
||||
|
[awk -v RS=\> ' { print $0 ">"}' <<+ | awk '/<TAG>/,/<\/TAG>/{ if ( /TAG>/) { next}; print}'
<FILE> www.unix.com Enhanced Mode <TAG> Hi </TAG> Enhanced Mode </FILE> + Hi First awk "normalizes' the data, making sure the ">" is the last part of a line, 2nd awk looks for the information between the beginning and end tags, but ignores the tags line themselves otherwise you would get <TAG> Hi </TAG> When you specified you only want the "Hi" |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|