linux下利用grep查看匹配的上下几行或前后几行

If you only want to match the upper and lower lines of the pattern, grep can implement it.

grep -5'parttern'inputfile / / print the first and last 5 matching lines
grep -c 5'parttern'inputfile / / print the first and last 5 matching lines
grep -a 5'parttern'inputfile / / print the last 5 lines of the matching line
grep -b 5'parttern'inputfile / / print the first 5 lines of matching lines

如果在只是想匹配模式的上下几行,grep可以实现。

grep -5 'parttern' inputfile //打印匹配行的前后5行
grep -C 5 'parttern' inputfile //打印匹配行的前后5行
grep -A 5 'parttern' inputfile //打印匹配行的后5行
grep -B 5 'parttern' inputfile //打印匹配行的前5行

Comments

Popular posts from this blog

Python Receiving and parse JSON Data via UDP protocol

ubus lua client method and event registration code demo/example