?
Solved

Replace a tag with sed

Posted on 2016-09-08
2
Medium Priority
?
68 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…
Suggested Courses

718 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