PDA

View Full Version : silly little awk qeustion



docetes
October 29th, 2009, 11:21 AM
I have the following text

<p><a href="http://www.blahblah.com/blah">bigeoino</a> posted a photo:</p>
<p><a href="http://www.www.blahblah.com/fdf/" title="test"><img src="http://www.blahblah.com/blah/3528/image93b_m.jpg" width="240" height="157" alt="nice" /></a></p>

When i run the following awk statement


awk 'BEGIN{FS="<img src=";RS="\/>"}/</{print $2}'


i get


"http://www.blahblah.com/blah/3528/image93b_m.jpg" width="240" height="157" alt="nice"

but i would like the code to stay enclosed in the <img and />

How would I go about this?

ghostdog74
October 29th, 2009, 11:55 AM
# awk '/img/{gsub(/.*img/,"");print "<img"$0}' file
<img src="http://www.blahblah.com/blah/3528/image93b_m.jpg" width="240" height="157" alt="nice" /></a></p>

docetes
October 29th, 2009, 12:05 PM
Cheers