pcregrep递归,显示周围的线条

时间:2013-01-05 14:34:46

标签: grep

我知道如何使用grep,但现在pcregrep。我试过了:

 pcregrep -M -1 -rl '."\n' 2012 -name en*.txt

但它不起作用?

基本上我希望它在文件夹2012中以递归方式显示名称为en_blahblahblah.txt的所有文件中显示前面一行和下面一行。但是我尝试了该命令并且它不起作用。 我需要使用pcregrep,因为grep不支持换行符。

1 个答案:

答案 0 :(得分:0)

使用-A lines-B lines选项。

[aman@aman test]$ pcregrep -M -B 2 -A 2 "C\nD" temp 
And failed to add the T and M;      Another called my grammar vile

C
D
                    And criticized my writing style.
Each day I scan each Subject line

来自手册页

   -A number, --after-context=number
             Output  number  lines of context after each matching line.


   -B number, --before-context=number
             Output  number lines of context before each matching line.
相关问题