Chinaunix

标题: 使用sed匹配某行,并新增一行,内容为。。。 [打印本页]

作者: johnson0418    时间: 2016-01-02 20:55
标题: 使用sed匹配某行,并新增一行,内容为。。。
[root ]$ cat quote.txt
The honeysuckle band played all night long for only $90.
It was an evening of splendid music and company.
Too bad the disco floor fell through at 23:00.
The local nurse Miss P.Neave was in attendance.

找到company这行,并新加一行内容为“Then suddenly it happed.”,但使用了下面的命令提示错误。(另外sed 无-i的参数)

sed "/company/a\Then suddenly it happened." quote.txt
sed: -e expression #1, char 11: Extra characters after command
作者: baby_神    时间: 2016-01-03 00:18
  1. [root@07 ~]# cat c
  2. The honeysuckle band played all night long for only $90.
  3. It was an evening of splendid music and company.
  4. Too bad the disco floor fell through at 23:00.
  5. The local nurse Miss P.Neave was in attendance.
  6. [root@07 ~]# sed "/company/a\Then suddenly it happened."  c
  7. The honeysuckle band played all night long for only $90.
  8. It was an evening of splendid music and company.
  9. Then suddenly it happened.
  10. Too bad the disco floor fell through at 23:00.
  11. The local nurse Miss P.Neave was in attendance.
复制代码
  1. [root@07 ~]# sed --version
  2. GNU sed version 4.1.5
  3. Copyright (C) 2003 Free Software Foundation, Inc.
  4. This is free software; see the source for copying conditions.  There is NO
  5. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
  6. to the extent permitted by law.
复制代码
可以啊,你那sed是不是坏了?还是版本问题,不行的话把sed升级下

作者: johnson0418    时间: 2016-01-03 00:36
回复 2# baby_神


    GNU sed version 3.02, 我的是定制系统,没有办法。
   我后来把我要加的内容生成一个文件 ,再通过sed把这个文件加到某行,已解决,谢谢了




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2