Filtering data from a standard input file or content matching mode. In addition to grep, there egrep, fgrep. grep egrep is an extension equivalent to grep -E. fgrep equivalent grep - F, with less. Usage: grep [OPTION] ... PATTERN [FILE] ... support regular described -E, - extended- regexp pattern is extended regular expressions (the ERE) -F, - Fixed - strings of the pattern is fixed newline string -G, - Basic- regexp mode is the basic regular expression (BRE) -P, - perl- regexp mode Perl regular expressions -e, - regexp = the pATTERN pattern matching, a plurality of modes can be specified match -f, - = file fILE acquisition mode from each line of the file -i, - ignore- Case ignore case -w, - Word- regexp pattern matches the entire word -x, - Line- regexp pattern matches the entire line -v, - invert- line match prints do not match Output control described -m, - max-count = NUM results output matching number num -n, - Line- Number print line number -H, - with- filename matches the file name of each print -h, - NO- filename does not output file name -o, - only- matching print content only match -q, - quiet do not output a normal message -s, --no- messages does not output an error message -r, - recursive This - = the include FILE_PATTERN --exclude = FILE_PATTERN --exclude- from = the FILE --exclude-the dir = the PATTERN recursive directory. Search only files that match. Skip file matching. Matching file skipped from file mode. Skip matching directory -c, - COUNT print only the number of lines per file that matches the contents of the control line Description -B, - before-context = NUM print matching the first few lines -A, - after-context = lines printed after NUM matching -C, - context = before and after printing the matched lines NUM --color [= the WHEN], font color matching blog address: HTTP: // lizhenliang.blog.51cto.com QQ group: 323 779 636 (Shell / the Python group development operation and maintenance) example: 1 ) b file output in the same line of a document grep # - Fab 2 ) b output file in a file different rows # grep -v - Fab . 3 ) a plurality of matching patterns # echo " a de BC " | xargs -n1 | grep -e ' a ' -e ' BC' A bc 4 ) remove blank lines or spaces http.conf file lines begin with the # # grep -E -v " ^ $ | ^ # " / etc / httpd / conf / the httpd.conf 5 ) matches the beginning are not case sensitive word # echo " a ABC " | xargs -n1 | grep - IA or # echo " a ABC " | xargs -n1 | grep ' [Aa] ' a a . 6 ) show only the matching string # echo " the this iS a the Test " | grep -o ' iS ' iS iS 7 top five results) output matching # seq. 1 20 is | grep -m . 5 -E ' [0-9] {2} ' 10 . 11 12 is 13 is 14 . 8 ) how much statistical matching row # SEQ . 1 20 is | grep -C -E ' [0-9] {2} ' . 11 . 9 ) matches the beginning of the character line b # echo " a de BC " | xargs -n1 | grep ' ^ b ' BC 10 ) to match the end of the character row and de output matching line # echo " a ab & ABCDE ABC ABCD " | -n1 xargs | grep -n ' de $ ' 5 : ABCDE 11 ) recursive search /ip etc directory contains the conf file suffix # grep -r ' 192.167.1.1 ' / etc --include * .conf 12 ) exclude search bak file suffix # grep -r ' 192.167.1.1 ' / opt --exclude * . BAK 13 is ) excluded from the file in the file # grep -R & lt ' 192.167.1.1 ' / opt --exclude- from file 14 ) match numbers 41 or 42 # SEQ 41 45 | grep -E ' . 4 [12 is] ' 41 42 15 ) match at least two characters # seq 13 | grep -E '[0-9] {2} ' 10 . 11 12 is 13 is 16 ) matches at least two characters of the word, the word of up to three characters # echo " A ab & ABCDE ABC ABCD " | xargs -n1 | grep -E -o -w ' [AZ] {2,3} ' ab & ABC . 17 ) matches all the IP # the ifconfig | grep -o -E " [0-9] l, 3} {\ [0-9] {l, 3} \.. . [0-9] {1,3} \ [0-9] {1,3} " 18 ) Print results matching row 3 and # SEQ . 1 10 | grep . 5 -A 3 . 5 . 6 . 7 . 8 . 19 ) to match the printing The results and the first three rows # seq 1 10 | grep 5-B . 3 2 . 3 . 4 . 5 20 is ). 3-line printing and before and after matches # SEQ . 1 10 | grep . 5 -C . 3 2 . 3 . 4 . 5 . 6 . 7 . 8 21 is ) not to be displayed with no error Output: # grep ' A ' ABC grep : abc: no SUCH File or Directory # grep -s ' a ' abc # echo $ ? 2 does not show the normal output: # grep -q ' a ' a.txt grep support base and the last chapter of the extended regular expression characters.