I know I can run commands against a match in sed
like so:
$ cat file
line1
line2
line3
line4
$ sed -e "/^line2/ s/^/# /" file
line1
# line2
line3
line4
Is it possible to run multiple commands, say s/^/#/
and s/$/ # invalid/
on the same match?
I tried adding them both but I get an error:
$ sed -e "/^line2/ s/^/# / s/$/ # /" file
sed: -e expression #1, char 18: unknown option to `s'
I tried using ;
but that seems to discard the initial match and execute on every line in the input:
$ sed -e "/^line2/ s/^/# / ; s/$/ # /" file
line1 #
# line2 #
line3 #
line4 #