Problem in string replace in unix

August 13, 2011 at 04:44:40
Specs: Macintosh
I have a file <<a.rpt>> with values below values.

aaa
bbb
ccc
<HTML>
<H1>sakthi</H1>
</HTML>

I am expecting out like below..(include "content type : text/html" before HTML tag strarts)
aaa
bbb
ccc
content type : text/html
<HTML>
<H1>test</H1>
</HTML>

please help on this.


See More: Problem in string replace in unix

Report •


#1
August 13, 2011 at 23:16:26
I am not a Mac guy, but this script works for GNU sed:

sed 's|^<HTML>|content type : text/html\n&|' a.rpt

Pre-GNU sed does not support using new-lines in a replacement.

If sed does not work, try this awk script:

awk ' {
    if($1 ~ /<HTML>/)
       print "content type : text/html"

   print $0
} ' a.rpt


Report •
Related Solutions


Ask Question