I hate SED - please help!!

Hi all

I have been googling for ages but with no prevail hence this new thread.

I would like to add a new line after a particular text string. For example, assume the original file contains the following text:

..
line1
line2
line3
..

I would like to insert the text string "additional_text" inbetween "line2" and "line3" so file will contain the following:

..
line1
line2
additional_text
line3
..

I have tried the following sed command with no luck:

sed -e 's/line2/line2\nadditional_text/g' original_file > new_file

Does anyone know what I should do?

Thanks very much
Robbie

Some old versions of sed may not support "\n". You may try giving a new line manually in the command like this.

sed 's/line2/line2\
 additional_text/g' original_file > new_file
$ sed '
/line2/ a\
Add this line after line2
' ro.txt

line1
line2
Add this line after line2
line3

$ sed '
2 a\
Add this line after 2nd line
'  ro.txt

line1
line2
Add this line after 2nd line
line3

//Jadu

Great Krishmaths

I tried what you said and it works a treat. Thanks very much