Search code examples
regexsedcygwin

Help with SED syntax : unterminated `s' command


Edit: I'm using CYGWIN/GNU sed version 4.1.5 on windows Vista and I want a case insensitive search

I want to use sed to replace inline, the following:

c:\DEV\Suite\anything here --- blah 12 334 xxx zzzzz etc\Modules etc

Edit: anything here --- blah 12 334 xxx zzzzz etc means anything could appear here. Sorry for omitting that.

In a file with lines like

FileName="c:\DEV\Suite\anything here --- blah 12 334 xxx zzzzz etc\Modules\.... snipped ...."

with a value I supply, say :

Project X - Version 99.98

So the file ends up with:

FileName="c:\DEV\Suite\Project X - Version 99.98\Modules\.... snipped ...."

My attempt:

c:\temp>sed -r -b s/Dev\\Suite\\.*\\Modules/dev\\suite\\simple\\/g test.txt

However I get the following error:

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

Thanks. Edit: I've already tried added quotes.


Solution

  • It's the '\\' before the '/'. Apparently you need 4 backslashes.

    sed -r -b "s/Dev\\\\Suite\\\\.*\\\\Modules/dev\\\\suite\\\\simple\\\\/g" test.txt
    

    I think the shell is interpreting the '\\' into a '\' before passing it to sed, and then sed is doing the same thing on what it gets.

    Single quotes would work, so:

    sed -r -b 's/Dev\\Suite\\.*\\Modules/dev\\suite\\simple\\/g' test.txt