bash的grep的换行符 [英] bash grep newline
本文介绍了bash的grep的换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
[编辑插入:可能的重复同样的海报的<一个href=\"http://stackoverflow.com/questions/1083601/reading-a-subset-of-the-lines-in-a-text-file-with-bash\">earlier问题?]
[Editorial insertion: Possible duplicate of the same poster's earlier question?]
您好,我需要从文件中提取:
Hi, I need to extract from the file:
first
second
third
使用grep命令,下面一行:
using the grep command, the following line:
second
third
应该如何grep命令样子?
How should the grep command look like?
推荐答案
而不是的grep
,您可以用 pcregrep
支持多行模式
Instead of grep
, you can use pcregrep
which supports multiline patterns
pcregrep -M 'second\nthird' file
-M
允许模式来匹配多个行。
-M
allows the pattern to match more than one line.
这篇关于bash的grep的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文