Solved

Replace a tag with sed

Posted on 2016-09-08
2
41 Views
Last Modified: 2016-09-08
I need to replace a tag by another one, but keep the text in between, i.e. change <tag1 whatever>some text</tag1> into <tag2 whatever>some text</tag2>. Is this possible using sed?
0
Comment
Question by:GeologyETH
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 41789721
S='<tag1 whatever>some text</tag1>'
echo "$S"| sed -e 's/<tag1/<tag2/' -e 's/<\/tag1/<\/tag2/'

If there's never a linefeed between the tags then this will do it as well:

echo "$S"|sed 's/<tag1\(.*\)<\/tag1\>/<tag2\1<\/tag2>/'
0
 

Author Comment

by:GeologyETH
ID: 41789754
works perfectly, thanks.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now