I'm trying to use sed to insert a # to a configuration file. I've tried:

sed 's/33/#' /path/to/file 

But get the output

sed: -e expression #1, char 6: unterminated `s' command

I've also tried

sed -i '33i#' /path/to/file

Which adds the # into line 33, but moves the text I want to comment down one line.

Can anyone point me in the right direction?

  • If you added the trailing slash to 's/33/#/', it would replace occurrences of 33 with #.
    – Melebius
    Jul 22 '19 at 12:53

The solution you're after is:

sed -i '33s/^/#/' /path/to/file

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.