Grep usage
1. Basic usage
Syntax: grep [Options] RegEx File
Here, RegEx is the regular expression file, which is the name of the text file to be matched. You can specify multiple
Eg:
$: Ls/usr/bin> dirlist-usr-bin.txt
$: Ls/sbin> dirlist-sbin.txt
$: Ls/usr/sbin> dirlist-usr-sbin.txt
$: Grep tou dirlist-bin.txt
Touch
Tou is a regular expression that matches rows containing the TOU string, because execution in shell command lines should avoid expansion before execution, and the standard writing should be
Grep 'tou' dirlist-bin.txt to avoid unnecessary errors.
2 options
-I case-insensitive
-V reverse matching
-L output the file name containing the matching string
-L output file names that do not contain matching strings
$ Grep-l 'tou '*
Dirlist-sbin.txt
Dirlist-usr-sbin.txt
-H: Only output matching file names
-N: Output matched rows
$ :~ /Jiangjian/NOTE/TEMP $ grep-N 'tou' dirlist-bin.txt
Dirlist-bin.txt: 141: Touch
3. [] usage
If you want to avoid shell extension, you can write regular expressions in "'" and "'". Here, you can use "[" and "]" to match certain character sets, if the match is successful, except for the two metacharacters "^" and "-", other metacharacters are not escaped, matches with ordinary characters,
$: Grep '[BG] Zip 'dirlist-*. txt
Dirlist-bin.txt: Bzip2.
Dirlist-bin.txt: bzip2recover.
Dirlist-bin.txt: Gzip
Note that dirlist-*. txt in the command line has been extended before execution.
Grep basic operations