Use regular expressions in various formats and usage
Commands that use regular expressions for search and search are commonly used: grep (search), egrep (Extended grep), and fgrep.
Grep: Use regular expressions, text information, and other conditions to retrieve information in a file and display lines containing matching strings.
Format: grep [Options] 'pattern' filename
Options: Option (omitted)
Pattern: Regular Expression and text
Filename: File Name
Option:
-I: case-insensitive characters
-- Color: color the matched string.
-O: only matching strings are displayed"
-V: displays unmatched rows.
-A #: displays the matched rows and the following # Rows (total # + 1 rows)
-B #: display the matched rows and the above # Rows
-C #: display the matched rows and the above # Rows and above # Rows (total # + 1 rows)
Pattern:
'.': Indicates a single arbitrary character.
'*': Indicates matching any character before
'. *': Any character of any length
'[]': A line that matches any single character
[: Alpha:] [: digit:] [: alnum:] [: lower:] [: Upper:]
'[^]': Match any row other than this character
\ {M, N \}: match the first character at least m times, at most N times
\? : Match the first character 0 or 1 time
\ <: Match the line with the first character after the word \>: match the line with the last character before the word
\ <String \>: match the row where the word 'string' is located
^: Match the row whose first line is its second character $: match the row whose last line is its first character
^ $: Matches blank rows
^ String $: the row that matches the entire 'string'
\ (String \): Group
Example: ^ \ (ABC \) [[: Space:] \ 1 $: match the line with the content 'abc abc'
\ 1 indicates the first group in the expression, \ 2: indicates the second group, and so on
Extension expression
Format: egrep [Options] pattern [files...]
{M, n} matches the first character at least m times and at most N times
+ Match the first character at least once. Similar to {1 ,}
() Group
| Or B | boy indicates B or boy (B | boy) indicates boy or boy
Other usage is similar to grep
Fgrep does not support regular expressions.
This article is from the "xpzz51" blog. For more information, contact the author!
Regular Expression format and usage