免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 19944 | 回复: 12
打印 上一主题 下一主题

sed: -e expression #1, char 0: unmatched `{' [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-04-24 19:08 |只看该作者 |倒序浏览
为什么执行下面的命令时会报错误 sed: -e expression #1, char 0: unmatched `{'

sed -i '/Removing/{n;a\\--->test;}' a.txt

论坛徽章:
0
2 [报告]
发表于 2012-04-24 19:25 |只看该作者
  1. The syntax of these commands is unusual for sed because they must be specified over multiple lines. The syntax follows:

  2. append [line-address]a\
  3. text
  4. insert [line-address]i\
  5. text
  6. change [address]c\
  7. text

复制代码
回复 1# phoebe_y_wang


   

论坛徽章:
0
3 [报告]
发表于 2012-04-24 19:52 |只看该作者
恩,谢谢指点哦~明白啦,试了一下分行,OK的,那我想要加一个这样的带双引号字符串: “/home/phoebe",  应该怎么写呢?
会遇到这样的错误:sed: -e expression #1, char 22: unknown command: `"'

回复 2# Perl_Er


   

论坛徽章:
1
辰龙
日期:2014-05-22 11:38:58
4 [报告]
发表于 2012-04-24 20:08 |只看该作者
  1. sed -i '/Removing/{n;a "\/home\/phoebe"
  2. > }'
复制代码

论坛徽章:
0
5 [报告]
发表于 2012-04-24 20:17 |只看该作者
没错,cool,谢楼上~ (∩_∩)回复 4# winway1988


   

论坛徽章:
0
6 [报告]
发表于 2012-04-24 21:03 |只看该作者
其实用 s/$/\n xxxxxx/ 也挺好的

论坛徽章:
0
7 [报告]
发表于 2012-04-25 09:36 |只看该作者
回复 2# Perl_Er


    我想问一下,我看到书上的语法也是必须在a,i,c后加\,然后在下一行输入
但是我测试
  1. sed '/str/aSTR' file
  2. sed '/str/a\STR' file

复制代码
都行呢

论坛徽章:
0
8 [报告]
发表于 2012-04-25 09:38 |只看该作者
回复 4# winway1988


    不是a后面必须跟\,而且必须分行吗??

论坛徽章:
0
9 [报告]
发表于 2012-04-25 10:30 |只看该作者
  1. Each of these commands requires a backslash following it to escape the first end-of-line. The text must begin on the next line. To input multiple lines of text, each successive line must end with a backslash, with the exception of the very last line. For example, the following insert command inserts two lines of text at a line matching "<Larry's Address>":

  2. /<Larry's Address>/i\
  3. 4700 Cross Court\
  4. French Lick, IN
  5. Also, if the text contains a literal backslash, add an extra backslash to escape it.[5]

复制代码
回复 7# g_programming


   

论坛徽章:
0
10 [报告]
发表于 2012-04-25 10:34 |只看该作者
回复 9# Perl_Er


    我看了的 它说这些命令每个都要求后面跟一个反斜杠用于转义第一个行尾,text必须从下一行开始,这就是说
  1. sed '/str/aSTR' file

  2. sed '/str/a\STR' file
复制代码
都是不满足语法的 但是确实能够执行啊?
我不知道我说对没?谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP