2

How to add some text before another with sed? With GNU sed on linux I can make it like that:

sed -i "/\;Marker/i some text" conffile

It puts "some text" before ";Marker". But in FreeBSD I get an error:

sed: 1: "/conffile ...": extra characters at the end of l command

I need analog to use it in FreeBSD.

rGA145
  • 419

1 Answers1

1

found this way:

sed -i'' -e $'/Marker/i\\\nblahblah\\\n' file

or

sed -i'' -e '/Marker/i\'$'\n''blahblah'$'\n' file
rGA145
  • 419
  • I think you only need to add an argument to the -i option, the rest of the script looks okay to me: sed -i '' '/;Marker/i some text' conffile. If your own answer works, accept it to close the question. – Philippos Jan 15 '18 at 16:26
  • That syntax does not work on FreeBSD sed. @Philippos – leo Aug 17 '23 at 03:31