grep Linux Advance hints

There are occasions when we need to look for a specific word or phrase yet we need to check certain number of lines before or after that. Here is the way to do it:

Use -A with grep for number of lines before matching line and -B for number of line after matching line.

Example1
ifconfig | grep -B 2 inet will outupt lines that will show you all of your interface names that have a IPv4 address.

Example2

nmap -sP 192.168.1.0/24 | grep -A 3 -B 2 9B:2B

You may also like