Home > database >  Unable to use sed command in Windows Command Prompt due to 'unterminated address regex'
Unable to use sed command in Windows Command Prompt due to 'unterminated address regex'

Time:11-24

I'm trying to run a sed command on a Windows machine from the command prompt (CMD.exe) but I am struggling to understand the regular expression and how to escape the string properly when running on Windows. Ideally, I want to develop a solution that works across UNIX and Windows.

sed is not available on Windows so I have installed it via the gnuWin32 project which works well.

The unix format for the command is:

sed -i '' -e 's/\\/_next/\\.\\/next/g' out/**.html

Through a process of trial an error I have managed to get this far:

sed -i \'\' -e \'s/\\/_next/\\.\\/next/g\' out/**.html

but I get an error: sed: -e expression #1, char 27: unterminated address regex

So there's definitely something wrong with my regex, probably the escaping of various parts? Any ideas how I might go about fixing this?

Update: I'm getting the code from here where unfortunately only Linux and OSX are covered.

CodePudding user response:

You need to use

sed -i "s/\\/_next/\\.\\/next/g" out/**.html

The Windows GNU sed does not require the '' empty argument after -i option, they can be safely removed.

Also, the sed command in Windows console should be used in double quotes.

  • Related