A brief introduction to the Linux grep command:
grep (Global search regular expression and print out of the line: Full search of regular expressions and print out the lines) is a powerful Linux text Search tool that uses regular expressions to search for text and print matching lines Come out.
Command format:
grep [option] Pattern file
grep [-ACINV] [--color=auto] ' Search for string ' filename
Options and Parameters:
1.-A: Searches binary text for data in the form of a text file.
2.-c: Calculates the number of times to find the ' search string '.
3. Ignoring case is placed differently, so case is considered the same.
4.-n: Output line number by the way.
5.-v: Reverse selection, which shows the line without the ' search string ' content.
6.--color = Auto: You can add a color display to the Found keyword.
Find the directory recursively based on the contents of the file:
1 grep ' findcontent ' * #在当前目录搜索带有 ' findcontent ' line of files 2 grep-r ' findcontent ' # Searches the current directory and its subdirectories for files of the ' findcontent ' line. 3 grep-l-R ' findcontent ' #在当前目录及其子目录搜索 ' findcontent ' files, but does not display matching rows, only matching files are displayed.
The combination of grep and regular expressions
1. Match a specified range of characters, such as ' [Gg]rep ' match grep and grep
Example: Grep-n ' t[ae]st ' filename.txt----> matches tast and test, indicating that we want to search for filename.txt and test two words in the tast file, and output line numbers.
2.^ indicates the beginning of the anchoring line, such as: ' ^grep ' matches all rows that begin with grep.
3.$ indicates that the end of the anchoring line is as follows: ' grep$ ' matches all rows ending with grep.
4.. Matches a non-newline character, such as: ' GR.P ' matches gr followed by an arbitrary character followed by P.
5. * Match 0 or more previous characters, such as: ' G*rep ' matches all one or more G characters followed by the rep line.
6. * Use together to represent any character
7. [^] matches a character that is not within the specified range, such as: [^g]oo search has oo lines, but do not want oo preceded by G.
Usage examples:
Example 1: Finding a process
Ps-ef | grep SVN
Example 2: Find the specified number of processes
Ps-ef | grep svn-c or Ps-ef | Grep-c SVN
Example 3: Search from a file by reading a keyword
Cat Test.txt | Grep-f Test2.txt
Example 5: Finding keywords from a file and adding color to keywords
grep ' Test '--color test.txt
Example 6: Find keywords from multiple files
grep ' Test ' test1.txt test2.txt
Example 7: Find the line content starting with G
Cast Test.txt | grep ^u
Example 8: Output line content that does not start with u
Cat Test.txt | grep ^[^u]
Example 9: Output line content ending in hat
Cat Test.txt | grep hat$
Example 10: Displaying a line of content that contains 9 or nine characters
Cat Test.txt | Grep-e ' 9|nine '
Company usage:
grep '. * 38 activities *. '--color/opt/web/dianshangwuxian_t_jzt/wf/logs/emcdsthirdservice.log
Original:
1.http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2856896.html
2.http://www.cnblogs.com/peida/archive/2012/12/17/2821195.html
The Linux grep command is detailed