与SED在比赛前删除所有行 [英] Remove all lines before a match with sed

查看:169
本文介绍了与SED在比赛前删除所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用sed来过滤文件列表。我有一个文件夹排序列表,我想一个特定后能得到所有行。要完成这个任务,我使用的解决方案,这里描述其中工程pretty以及与任一输入我试过,但它当比赛是在第一行不起作用。在这种情况下的sed将删除所有的输入行

I'm using sed to filter a list of files. I have a sorted list of folders and I want to get all lines after a specific one. To do this task I'm using the solution described here which works pretty well with any input I tried but it doesn't work when the match is on the first line. In that case sed will remove all lines of the input

这是一个例子:

(ssh) fabio@s2 : ~
[0] % ls -1 /
bin
boot
...
sys
tmp
usr
var
vmlinuz

(ssh) fabio@s2 : ~
[0] % ls -1 / | sed '1,/tmp/d'
usr
var
vmlinuz

(ssh) fabio@s2 : ~
[0] % ls -1 / | sed '1,/^bin$/d'
# sed will delete all lines from the input stream

我应该如何改变命令还考虑了极限情况下,当第一行匹配regexp?

How should I change the command to consider also the limit case when first line is matched by regexp?

BTW 的sed'1,1d'正确工作并删除第一个行只。

BTW sed '1,1d' correctly works and remove the first line only.

推荐答案

试试这个(GNU只有SED):

try this (GNU sed only):

sed '0,/^bin$/d'

..输出是:


$sed '0,/^bin$/d' file
boot
...
sys
tmp
usr
var
vmlinuz

这篇关于与SED在比赛前删除所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆