Sed and variables


Sed is a really awesome part of linux, allowing to insert and amend text where ever you can find it! Had some niggles trying to get it to like my bash variable though however with the below I got it to do the trick, seems to be those pesky quotation marks that are causing problems!!

Added an example below which will post a variable in between an XML tag, handy for working with APIs or other craziness.

Example

XML

<somexmltaghere>PLEASE INSERT ME HERE :d!!<somexmltaghere>

Sed

sed 's/<\/somexmltaghere>/'"$variablehere"'&/' test.xml 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s