LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1012|回复: 5

新手求助,sed能实现这样的功能吗?

[复制链接]
发表于 2005-12-7 21:30:00 | 显示全部楼层 |阅读模式
对一个文件test,查询其中以hello world开头的行
并删除这行以及紧接这行以后的两行后,保存到新文件test.new

请教该怎么做啊?脸红脸红!
发表于 2005-12-8 09:12:15 | 显示全部楼层
sed '/^hello\ world/{N;N;d}' test>text.new

注意:连续两个开头为hello world的行的话,则以第一个为准
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-12-8 10:19:32 | 显示全部楼层
Post by HuiCai
sed '/^hello\ world/{N;N;d}' test>text.new

注意:连续两个开头为hello world的行的话,则以第一个为准


不行啊,提示错误
sed: command garbled: /^hello\ world/{N;N;d}
回复 支持 反对

使用道具 举报

发表于 2005-12-8 11:10:56 | 显示全部楼层
命令:
  1. sed '/^hello\ world/{N;N;d}' test>test.new
复制代码

原始文件test:
  1. hello world开头的行
  2. xxxx
  3. xxxx
  4. xxxxx
  5. hello world开头的行
  6. xxx
  7. xx
  8. hello world开头的行
  9. xxxxxxxxxxxx
  10. xxxxxxxxxxxxxxxxxxx
  11. xxxxxxxxxxxxxxxxx
  12. xxxxxxxxxxxx
  13. hello world开头的行
  14. hello world开头的行
  15. xxxxxxxxxxxxxxxxxx
  16. xxxxxxxxxxxxxx
复制代码

输出结果:
  1. xxxxx
  2. xxxxxxxxxxxxxxxxx
  3. xxxxxxxxxxxx
  4. xxxxxxxxxxxxxx
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-12-8 12:24:39 | 显示全部楼层
我就是错误啊,不知道为什么原因。
我的是solaris,csh
回复 支持 反对

使用道具 举报

发表于 2005-12-8 12:44:34 | 显示全部楼层
也许是sed版本或者其余原因
我的linux下的csh没问题

那你去搜索一下吧,有不少是这个问题,仔细找答案吧
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表