Search code examples
batch-filesedgnuwin32

Batch File using sed in windows - unexpected append instead of replace


I've been tasked with migrating a group of batch scripts to Windows 7 (from XP) and have had a few problems using sed for substitution. What i need the line to do is find LogPath and anything inside the double quotes should be replaced with ABC (just for testing - will actually be a UNC path).

However instead I'm getting two strange problems:

  • it's deleting the first double quote
  • more importantly it isn't actually replacing anything inside the quotes, but instead is just appending to this string

Here is the relevant line of the script:

sed \\fs-bri-01\9732\9732.hfls -i -e s,LogPath="*.",LogPath="ABC",g

This script works on Windows XP but not Windows 7.


Solution

  • Well figured a work around posting it below for anyone stuck in the same situation.

    sed \\fs-bri-01\9732\9732.hfls -i -e "s/LogPath=\"[\:A-Z0-9a-z_\\\/\.\ ]*\"/LogPath=\"ABC\"/g"