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.

1

found this way:

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

or

sed -i'' -e '/Marker/i\'$'\n''blahblah'$'\n' file
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.