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.

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


nmap -sP | grep -A 3 -B 2 9B:2B

You may also like