关于sed的用法。

2013-10-19 10:43:14 +08:00
 gouera
[root@localhost ~]# sed '/aa/,10/d' a.txt
sed: -e expression #1, char 8: unknown command: `/'


删除从含有aa的行到第10行, 不是这样写么,怎么会报错。
如果把10后面的d去掉,效果又不是一样的了。
求帮忙啊。
3602 次点击
所在节点    Linux
7 条回复
h2ero
2013-10-19 11:03:44 +08:00
sed '/aa/,10d' a.txt
gouera
2013-10-19 11:38:17 +08:00
[root@localhost ~]# wc -l a.txt
33 a.txt
[root@localhost ~]# sed '/aa/,10d' a.txt
[root@localhost ~]#


@h2ero 貌似不对啊。 这个文件有33行。 删了10行还有23啊。。 怎么没输出了。
kemad
2013-10-19 17:53:54 +08:00
man sed

addr1,+N
Will match addr1 and the N lines following addr1.
rrfeng
2013-10-19 21:06:44 +08:00
[rr@mypc ~]#seq 10|sed '/3/,5d'
1
2
6
7
8
9
10
[rr@mypc ~]#^
rrfeng
2013-10-19 21:07:30 +08:00
你是要删除 /aa/ 后的10行

还是 /aa/ 到 第 10 行
gouera
2013-11-30 16:13:16 +08:00
@rrfeng 删除1-10行里面含有/aa/的行啊。
rrfeng
2013-11-30 17:36:34 +08:00
@gouera

1,10{/aa/d}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://tanronggui.xyz/t/86094

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX