It looks like your version of sed
requires a suffix argument for the -i
option. That means it's probably on a Mac or FreeBSD machine.
sed
is then interpreting your sed script as the suffix, and the filename as the sed script....hence the error message Invalid command code .
, because that's the first character of the filename.
Try:
sed -i .bak 's/\([^.]*\)\.css/\1.min.css/g' ./bobby/templates/layout.html
I've added a backslash to escape the .
in the LHS of the s/// command (otherwise it will match any character, not just a literal .
), and got rid of the ;
at the end of the filename - that would only be needed if there was more than one command in the same line.
The sed script will do an in-place edit of the file, and make a backup as .../layout.html.bak
Alternatively, you can do it with perl. e.g.
perl -i -p -e 's/([^.]*)\.css/$1.min.css/g' ./bobby/templates/layout.html
BTW, the regular expressions used in both the sed and perl versions may change more than you expect, because it's unlikely that there will be just filename.css
on a line by itself in a .html
file. I'd test it first without the -i
option.
You may want something more like s:(/[^.]*)\.css:$1.min.css:g
, so that it only changes a filename if it's immediately preceded by a slash character. It's impossible to be more specific than that without seeing what your actual input file looks like.