帮助SED语法:unterminated`s'命令 [英] Help with SED syntax : unterminated `s' command

查看:8832
本文介绍了帮助SED语法:unterminated`s'命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

修改:我在Windows Vista上使用CYGWIN / GNU sed版本4.1.5,并且我想要不区分大小写的搜索

想要使用sed替换inline,如下:

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


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

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

编辑:这里的任何内容--- blah 12 334 xxx zzzzz等等意味着任何可能出现在这里。

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

在包含

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

使用我提供的值,例如:

with a value I supply, say :


- 版本99.98

Project X - Version 99.98

所以文件最后是:

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

我的尝试:

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. I've already tried added quotes.

推荐答案

这是'\\'在'/'之前。显然您需要4个反斜杠。

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

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



我认为shell正在将'\\'解释为'\'

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

这篇关于帮助SED语法:unterminated`s'命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆