Solved

Replace a tag with sed

Posted on 2016-09-08
2
51 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is an explanation of a simple data model to help parse a JSON feed
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

856 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