Solved

Replace a tag with sed

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

785 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