[olug] need some quick help with sed

Obi-Wan obiwan at jedi.com
Fri Dec 18 15:09:45 UTC 2009


> i'm trying to strip an xml value into a variable in a bash script.
> 
> postID="$(echo `cat ./data.xml | grep postID`)"
> 
> but this gives me the entire line:    <postID>999999</postID>
> 
> i need $postID to equal 999999 and i've been trying to learn how to do this
> with sed, but anything i try just outputs the entire line with the xml tags.

This will remove all the XML tags from a line:

postID=`cat ./data.xml | sed -e 's/<[^>]*>//g'`

-- 
Ben "Obi-Wan" Hollingsworth                             obiwan at jedi.com
   The stuff of earth competes for the allegiance I owe only to the
     Giver of all good things, so if I stand, let me stand on the
       promise that You will pull me through.  -- Rich Mullins



More information about the OLUG mailing list