I’d like to insert a line before a pattern with sed:
– Insert ‘XmlRootElement(name=”ABC”)’ before “public class”
This is the script:
'/public class/i\@XmlRootElement(name="ABC")'
However I got error when I run this:
sed -e script testfile.txt
sed: -e expression #1, char 13: Unterminated `s' command
Can anyone help me?
Thanks
For the sed’s I’m used to, you have to include a line break after your
i\, and ‘terminate’ the insert with a blank line, i.e.Note, the blank line after your new inserted text.
Note, make sure you don’t get any spaces at the end of the line, after the
i\.As I realize now that you’re keeping your sed in a separate script file, the formatting constraints apply there too, just remove the
''pair surrounding the code.And more importantly, your script is failing because you use
-efor a sed script file, use-eis used if your embedding your sed script in-line, My 1st solution above could be pre-pended with-e.Edit Fixed references to
a\to `i\’. Doahhope this helps.