[olug] need some quick help with sed

Kevin D. Snodgrass kdsnodgrass at yahoo.com
Fri Dec 18 09:39:30 UTC 2009


--- On Fri, 12/18/09, DYNATRON tech <dynatron at gmail.com> wrote:

> From: DYNATRON tech <dynatron at gmail.com>
> Subject: [olug] need some quick help with sed
> To: "Omaha Linux User Group" <olug at olug.org>
> Date: Friday, December 18, 2009, 12:58 AM
> 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.
> any suggestions? after 10 hours of coding in one day sed
> tutorials are just
> making my head spin.

Way past my bedtime, but here is a quick hack that does work:
 
postID="$(echo `grep postID data.xml |sed "{s/<postID>//}"|sed "{s/<\/postID>//}"`)"

echo $postID


I know there is a better way... sed is a wonderful tool, wish I could remember more of what it can do.  But all the useful docs seem to be in "info" format nowdays, which I despise at a level most people cannot understand.  (info sucks big donkey *&^$@!!!)


zzzzzzzzzzzzzzzzzz....

Kevin D. Snodgrass



      



More information about the OLUG mailing list