GREP is the abbreviation for global search Regular Expression and Print out of the line.
1. Basic usage of GREP commands
Command format: grep [options] [mode] [file ...]
Options |
Significance |
-C |
Output only the number of matching rows |
-I. |
Ignore case when searching |
-H |
Do not display file names when querying multiple files |
-L |
Lists only matching file names, not specific matching rows |
-N |
List all matching rows and display line numbers |
-S |
Do not display error messages that do not exist or have no matching text |
-V |
Display all lines that do not contain matching text |
-W |
Match Whole word |
-R |
Recursive search not only searches the current working directory, but also searches subdirectories |
-E |
Support for extended regular expressions |
-F |
Regular expressions are not supported and are matched by the literal meaning of the string |
Note: you need to enclose the pattern in double quotes as long as the pattern contains spaces.
grep Multi-file operation (AA BB for two files)
2. The meaning and usage of grep options 2.1-c options
In Aa,bb two files, there are two lines containing the Hello
2.2-n Options
The 1th line in the Aa,bb file contains Hello and prints out the information
2.3-v Options
2.4-i Options
Search in AA files for case-insensitive Hello all lines
2.5-l Options
Search all files in the current directory containing the text lines of Hello, listing only the file names
2.6-s Options
2.7-r Options
2.8-w and-X options
When the-w option is added, * is interpreted as a normal character.
-X means matching an entire row, which results when the file has an entire line of content to match.
2.9-q Options
Plus the-q option no longer outputs the result, but the exit status indicates success.
Exit Status 0 Indicates a successful search, exit status 1 indicates that a line of text that satisfies the pattern is not searched, and exit status 2 indicates that the command or program was not executed due to an error.
3 grep and regular expressions
3.1 Matching the beginning of the line
3.2 Set case
-I can ignore the case, or you can use [] to implement
3.3 Match repeating characters
Show h starts, repeats h any time, and the letter is E
3.4 Escape Character
Escape character \ Mask its meaning
Regular Expression 2--grep command