如何忽略所有线路在bash发生在比赛前? [英] How to ignore all lines before a match occurs in bash?
问题描述
我想忽略在bash在比赛前发生的所有线路(也忽略匹配线的输入的例子是
R1-01.sql
R1-02.sql
R1-03.sql
R1-04.sql
R2-01.sql
R2-02.sql
R2-03.sql
如果我符合 R2-01.sql
在这个已经排序输入我想获得
R2-02.sql
R2-03.sql
方法很多可能的。例如:假设你的输入是LIST.TXT
PATTERN =R2-01.sql
sed的0 / $ PATTERN / D< LIST.TXT
因为,在 0,/模式/
只适用于GNU sed的,(例如不能在OS X的作品),这里是一个的篡改解决方案。 ;)
PATTERN =R2-01.sql
(回声伪线至所述起动;猫 - )下; LIST.TXT | sed的1 / $ PATTERN / D
这将一个虚拟的行添加到开始,所以真正的模式必须上线1或更高,因此 1,/模式/
将作品 - 删除一切从第1行(虚设的)到图案
或者可以将图案打印后线和删除第一,如:
SED -n'/模式/,$ P'< LIST.TXT | SED1D
使用awk,例如:
的awk'/模式/,0 {如果(/模式/!)打印}'< LIST.TXT
或我最喜欢的使用下一个Perl的命令:
的perl -ne'打印除非1 ../模式/'< LIST.TXT
删除1.st线时,该模式是在一号线...
另一种解决方案是反删除,反向
尾-r< LIST.TXT | SED'/模式/,$ D'|尾-r
如果您有 TAC
命令用它来代替尾-r
的interesant事情比 /模式/,$ D'的作品就上线,但
1,/模式/ D`不会做第一个。
I would like ignore all lines which occur before a match in bash (also ignoring the matched line. Example of input could be
R1-01.sql
R1-02.sql
R1-03.sql
R1-04.sql
R2-01.sql
R2-02.sql
R2-03.sql
and if I match R2-01.sql
in this already sorted input I would like to get
R2-02.sql
R2-03.sql
Many ways possible. For example: assuming that your input is in list.txt
PATTERN="R2-01.sql"
sed "0,/$PATTERN/d" <list.txt
because, the 0,/pattern/
works only on GNU sed, (e.g. doesn't works on OS X), here is an tampered solution. ;)
PATTERN="R2-01.sql"
(echo "dummy-line-to-the-start" ; cat - ) < list.txt | sed "1,/$PATTERN/d"
This will add one dummy line to the start, so the real pattern must be on line the 1 or higher, so the 1,/pattern/
will works - deleting everything from the line 1 (dummy one) up to the pattern.
Or you can print lines after the pattern and delete the 1st, like:
sed -n '/pattern/,$p' < list.txt | sed '1d'
with awk, e.g.:
awk '/pattern/,0{if (!/pattern/)print}' < list.txt
or, my favorite use the next perl command:
perl -ne 'print unless 1../pattern/' < list.txt
deletes the 1.st line when the pattern is on 1st line...
another solution is reverse-delete-reverse
tail -r < list.txt | sed '/pattern/,$d' | tail -r
if you have the tac
command use it instead of tail -r
The interesant thing is than the /pattern/,$d' works on the last line but the
1,/pattern/d` doesn't on the first.
这篇关于如何忽略所有线路在bash发生在比赛前?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!