grep: For fuzzy lookups, in standard input or file
Format: grep [option parameter] ... PATTERN | FILE ...
Option parameter Description:
- E,--extended-regexp PATTERN is an extensible regular expression
-E,--regexp=pattern using PATTERN for matching operations
-F,--file=file gets the PATTERN from file
-I,--ignore-case ignore case
-W,--word-regexp mandatory PATTERN only matches words exactly
-X,--line-regexp force PATTERN to match only one line exactly
-Z,--null-data a 0-byte data row, but not a blank line
-C,--count only outputs the count of matching rows
-H,--no-filename does not display file names when querying multiple files
-H,--with-filename display file name
- N,--line-number matching line number
-O,--only-matching displays only matching content
-L,--files-with-matches only output filenames that contain matching characters
-L,--files-without-match only output mismatched filenames
-S,--no-messages does not display information that does not exist or matches the error
-V,--invert-match displays lines that do not contain matching text
"\<" and "\>" respectively mark the beginning and end of the word.
' ^ ': refers to a matching string at the beginning of the line
' $ ': refers to a matching string at the end of the line
grep " \<kim " kimbo_test.sh A string starting with a #匹配 Kim,kimbo,kimko, etc. grep " kim\> " kimbo_test.sh # Kim,mathkim,kobekim, etc. end of string grep " ^kim " kimbo_test.sh #行首以kim开头 grep"kim$" kimbo_test.sh #行尾以kim开头
Regular expressions
1. Match a single character
grep "\<1[0-9]" kimbo_test.sh #匹配以1开头的数字, the following character remains a number
2. Match repeating characters
grep "mf\{3\}" kimbo_test.sh #匹配以m开头, followed by three F content
3. Match 8-bit numeric date (YYYYMMDD)
grep '^[12]\{1\}[0-9]\{7\}$' kimbo_test.sh #强匹配 1 or 2 start date, such as 19901001,20171001, etc.
Shell grep Command Daquan