模式:
> AAAAA
> BBBBB
> CCCCC
注意:
当找到模式AAAAA或BBBBB时,我想只打印包含AAAAA或BBBBB的那一行.
当找到模式CCCCC时,我想打印包含CCCCC下一行的那一行.
例:
LONG.txt:
bla bla bla bla bla bla something something AAAAA something somethingbla bla bla bla something something CCCCC something somethingbla bla bla bla bla bla bla bla bla bla bla bla something something BBBBB something somethingbla bla bla bla bla bla something something AAAAA something somethingbla bla something something AAAAA something somethingbla bla something something BBBBB something somethingbla bla bla bla bla bla something something CCCCC something somethingbla blabla blabla bla
输出应该是:
something something AAAAA something somethingsomething something CCCCC something somethingbla bla something something BBBBB something somethingsomething something AAAAA something somethingsomething something AAAAA something somethingsomething something BBBBB something somethingsomething something CCCCC something somethingbla bla
我尝试的是:
grep -B0 "AAAAA" LONG.txt > SHORT.txtgrep -B0 "BBBBB" LONG.txt > SHORT.txtgrep -B1 "CCCCC" LONG.txt > SHORT.txt
但这并没有给我想要的输出.
解决方法 awk’/ AAA | BBB | CCC / {print; if($0~ / CCC /){getline;打印;}}’ 总结以上是内存溢出为你收集整理的linux – 如何组合多个grep命令?全部内容,希望文章能够帮你解决linux – 如何组合多个grep命令?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)