免费注册 查看新帖 |

Chinaunix

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

[学习共享] 使用sed匹配某行,并新增一行,内容为。。。 [复制链接]

论坛徽章:
4
每日论坛发贴之星
日期:2015-12-02 06:20:00程序设计版块每日发帖之星
日期:2015-12-12 06:20:00程序设计版块每日发帖之星
日期:2015-12-15 06:20:00程序设计版块每日发帖之星
日期:2015-12-19 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-01-02 20:55 |只看该作者 |倒序浏览
[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

论坛徽章:
20
程序设计版块每日发帖之星
日期:2015-10-11 06:20:0015-16赛季CBA联赛之山东
日期:2016-05-28 18:18:5615-16赛季CBA联赛之新疆
日期:2017-04-12 22:55:4715-16赛季CBA联赛之青岛
日期:2017-06-26 18:30:0315-16赛季CBA联赛之四川
日期:2017-09-04 12:27:0315-16赛季CBA联赛之福建
日期:2018-02-09 14:28:3315-16赛季CBA联赛之同曦
日期:2018-04-17 12:43:3415-16赛季CBA联赛之浙江
日期:2018-07-14 13:27:4015-16赛季CBA联赛之吉林
日期:2018-09-13 15:48:2915-16赛季CBA联赛之新疆
日期:2016-05-07 05:05:3215-16赛季CBA联赛之八一
日期:2016-03-14 12:32:06程序设计版块每日发帖之星
日期:2015-12-12 06:20:00
2 [报告]
发表于 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升级下

论坛徽章:
4
每日论坛发贴之星
日期:2015-12-02 06:20:00程序设计版块每日发帖之星
日期:2015-12-12 06:20:00程序设计版块每日发帖之星
日期:2015-12-15 06:20:00程序设计版块每日发帖之星
日期:2015-12-19 06:20:00
3 [报告]
发表于 2016-01-03 00:36 |只看该作者
回复 2# baby_神


    GNU sed version 3.02, 我的是定制系统,没有办法。
   我后来把我要加的内容生成一个文件 ,再通过sed把这个文件加到某行,已解决,谢谢了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP