Linux grep Command Extracting Text by Keyword

grep command is used to display matching keyword with their specified files .
Example now in the /etc/passwd file it contain lot of user password and their user name now I like to filter name user2 in these case Linux grep command has been used.
[root@localhost ~]# vim /etc/passwd
[root@localhost ~]# grep 'user2' /etc/passwd
user2:x:504:504::/home/user2:/bin/bash

Linux grep it has the various option –i to search case insensitively
grep-n to print the number of matches line
Example
[root@localhost ~]# grep -n 'user2' /etc/passwd
40:user2:x:504:504::/home/user2:/bin/bash
-v print lines not containing patter
-Ax to include the x lines after each match
-Bx to include the x line before each match

Related post