Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find and Insert

Status
Not open for further replies.

iaresean

Programmer
Mar 24, 2003
570
ZA
Hello All;

I am trying to insert about 4 lines after a specific sentence in the file. This sentence may not necessarily be on the same line in the file every time. How would I do this? I tried using a sed but it didn't print out the new lines.

I want for example:
Harry is

To become:
Harry is
no pleased
as he
cannot see
the...

This is how I tried it using sed:
infile="harry.txt"

sed -e 'sHarry is!Harry is\nno pleased\nas he\ncannot see\nthe...!g' $infile.$$ >$infile && rm $infile.$$

But this printed the following:
Harry isnno pleasednas hencannot seenthe...

I tried double slashing but that just printed:
Harry is\nno pleased\nas he\ncannot see\nthe...

Any ideas how to do this, maybe recommendations of a different method?

Any and all help greatly appreciated.

Sean. [peace]
 
Try using awk instead...

awk '{print}/Harry is/{print "no pleased\nas he\ncannot see\nthe..."}' infile
 
With sed :
[tt]
sed -e '/Harry is/ano pleasedas hecannot seethe...' $infile.$$ >$infile [/tt]

Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top