문제

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.

도움이 되었습니까?

해결책 2

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"

다른 팁

Maybe the problem comes from the UNC path:

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

But maybe the problem comes from the quote characters and the way sed gets its argv array. Then you can try:

sed -i -e "s/LogPath=\".*\"/LogPath=\"ABC\"/g" \\fs-bri-01\9732\9732.hfls
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top