Reputation: 3962
I once write a simple sed command like this
s/==/EQU/
while I run it in command line:
sed 's/==/EQU' filename
it works well, replace the '==' with 'EQU', but while I write the command to a script file named replace.sed
, run it in this way:
sed -f replace.sed filename
there is a error, says that
sed: file replace.sed line 1: unknwon option to 's'
What I want to ask is that is there any problem with my script file replace.sed while it run in windows?
Upvotes: 1
Views: 3631
Reputation: 882686
The unknown option is almost invariably a rogue character after the trailing /
(which is missing from your command line version, by the way so it should complain about an unterminated command).
Have a look at you replace.sed
again. You may have a funny character at the end, which could include the '
if you forgot to delete it, or even a CTRL-M DOS-style line ending, though CygWin seems to handle this okay - you haven't specified which sed
you're using (that may help).
Okay, based on your edit, it looks like one of my scattergun of suggestions was right :-) You had CTRL-M at the end of the line because of the CR/LF line endings:
At the end of each line in the
*.sed
file, there was a'CR\LF'
pair, and that the problem, but you cannot see it by default, I use notepad to delete them manually and fix the problem. But I have not find a way to delete it automatically or do not contain the'new-line'
style while edit a new text file in windows.
You may want to get your hands on a more powerful editor like Notepad++ or gVim (my favourite) but, in fact, you do have a tool that can get rid of those characters :-) It's called sed
.
sed 's/\015//g' replace.sed >replace2.sed
should get rid of all the CR
characters from your file and give you a replace2.sed
that you can use for your real job.
Upvotes: 3