sed adding a new line not working

sed '/patternstring/ a\ new line string' file1

The above code is not working even with the i option....
it shows sed grambled if '\' after new line string is not being used....after using no changes it is displaying..Pls help

Use code tags for code and data sample.

Try

sed 's/patternstring/\n new line string/' file
1 Like

it is still not working:(:(:frowning:

Try placing what follows the backslash on the next line.

That is absolutely useless feedback. Tell us which sed implementation and operating system you're using. Show us the command you ran. Show us the data that's the input for the command. Show us the incorrect output that is being generated. And, finally, show us the correct output that you desire.

A lot of sed implementations (and the POSIX standard) do not support the \n newline escape sequence in replacement text. The portable approach is to use a backslash followed by a literal newline.

Regards,
Alister

The file which is used is

/abc/apps/cobbbbbb/apps/abadv/binder/axyz.bnd
/abc/apps/cobbbbbb/apps/abbrio/binder/na6115.bnd
/abc/apps/cobbbbbb/apps/abbrio/binder/kc22.bnd
/abc/apps/cobbbbbb/apps/abbrio/binder/tr4823.bnd
/abc/apps/cobbbbbb/apps/abcmp/binder/cpc0105.bnd

The commads which I ran through are:

sed '/axyz.bnd/ a\grant permissions given  ' file1 

and

sed '/axyz.bnd/  i\grant permissions given  ' file1

..
If above commands are given it is showing an error so i added a '\'

sed '/axyz.bnd/  i\grant permissions given \ ' file1

..This time no error but no output..Pls help

Double post, continue here: