Linux grep command

  

The grep command is called global search regular expression (RE) and print out the line, which is a comprehensive search for regular expressions and prints the lines. It can use regular expressions to search for text and print out matching lines.

Syntax:

grep [-acinv] [--color=auto] 'Search String' File Name

Parameter Explanation:

- a : Search the binary file as a text file

-c : Calculate the number of times the 'string to be searched' is found

-i :Ignore the difference between upper and lower case

-n : By the way, output line number

-v : Reverse selection, that is, the line that shows no 'to-be-searched string' content

--color=auto : will find Keyword part plus color display

Example:

Both are demonstrated in server.properties under /bigdata/kafka/kafka_2.11-0.9.0.1/config/

1, find the line with zookeeper from the server.properties file and output


2, find the line with zookeeper from the server.properties file and output, and 1 , display zookeeper in color; 2, display line number


3, find the line with zookeeper from the server.properties file and output, and 1, the zookeeper is displayed in color; 2, display line number; 3, ignore case


or


4, from server.propert Find the line with zookeeper in the ies file, and 1, count the number of occurrences; 2. ignore the case


5. Search for files with 'zookeeper' line in the current directory


6. Search for files with 'zookeeper' line in the current directory and its subdirectories



7. In the current directory Search for files with 'zookeeper' lines in its subdirectories, but do not display matching lines, only show matching files


There are regular expressions, which are waiting to be continued!

Copyright © Windows knowledge All Rights Reserved