Results 1 to 5 of 5
I'd like to automate formatting some text.
So I hope someone can help me out on this as googling didn't help me much.
I'd like to find out how to ...
- 11-01-2007 #1Just Joined!
- Join Date
- Oct 2006
- Posts
- 29
Wrap tag around regex
I'd like to automate formatting some text.
So I hope someone can help me out on this as googling didn't help me much.
I'd like to find out how to wrap a tag around regex.
For example if I have word "Title" in the text to get something like <div id="title>Title</div>. I would know how to handle it if it was just "Title".
But in most cases I have "Title 2" or "Title 2 & 3" so I would need something to insert
<div id="title"> above the line containing the regex and to insert </div> under that line to cover complete title.
- 11-01-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
The context of your situation is not clear, it is best to include a sample of the input and desired output.
Regards
- 11-01-2007 #3Just Joined!
- Join Date
- Oct 2006
- Posts
- 29
Ok, I'll try to clarify. To simplify let's say I have 3 songs in a text document. And they look something like this:
Code:Song 1 Some lyrics more lyrics and some more
Code:Song 2 Some lyrics more lyrics and some more
I'd like to make a script which would allow me insert opening div tag before a line that contains "Song" and closing tag after that line. Regardless of other characters which that line might contain, like number 1 or word "Third".Code:Third Song Some lyrics more lyrics and some more
To get something like this:
I hope that makes it more clear.Code:<div id="title"> Song 1 </div> Some lyrics more lyrics and some more
- 11-02-2007 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
I'm not on a linux box so I can't test it out, but try this:
RegardsCode:awk '/Song/{print "<div id=\"title\">";print;print "</div>";getline} 1' file
- 11-02-2007 #5Just Joined!
- Join Date
- Oct 2006
- Posts
- 29
Thanks a lot Franklin52, that does the job.


Reply With Quote