2015-07-12 51 views
1

我使用下面的命令來搜索文本用grep檢索模式匹配後,接下來的2行文字:用grep

grep --include=*.{php,py} -rnw 'DIR' -F -e 'TEXT' 

考慮以下文字:

This is so funny 
This is pyramid 
Hello World 
How are you 

如何修改如果我指定'funny'作爲匹配表達式,上面的grep命令(或者是否有其他選擇)可以獲取下兩行代碼?

grep --include=*.{php,py} -rnw 'DIR' -F -e 'funny' 

回答

2

您可以使用grep -A <number>獲得匹配後的行數。