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
    Commented Jul 22, 2019 at 12:53

1 Answer 1


The solution you're after is:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .