I want to delete in a file each line beginning by '#'. I ran that (I am using osx)
sed -i '' -e 's/#.*/d' file
but I get this error message :
sed: 1: "s/#.*/d
": unescaped newline inside substitute pattern
The s command in sed means "substitute" and it takes two arguments:
s/pattern/replacement/
What you want to do is just to match lines starting with # and delete them, so you need the sed program:
/^#/d
Note that the pattern needs to start with ^ (meaning "start of line") otherwise it will match a # anywhere in the line.
As stated by Gareth Rees above, the correct command is:
sed '/^#/ d' file
This good sed tutorial contains your question as an example:
sed -i '/^#/d' file.sed -i '/^#/d' file→sed: 1: "file": invalid command code f-ioption...sedis happy with the command I gave... are you sure you didn't mistype it? Besides, that command is exactly the one you gave in your answer:D.sedis BSD-ish, and that means that the-ioption requires an argument.