Grep
-I ignores case
--color Plus Color
-V shows rows that are not matched to
-O displays only the string that is matched to
Grep-o ROOT/ETC/PASSWD | Wc-l find how many root strings there are
-e Use extended regular expression egrep=grep-e
-A # grep-a 2 ' ^core ID '/proc/cpuinfo
-B # grep-b 2 ' ^core ID '/proc/cpuinfo
-C # grep-c 2 ' ^core ID '/proc/cpuinfo
Regular Expressions: Basic REGEXTP Basics
Extended regextp Extension
Regular expressions
. Represents any single character
* indicates that matches its preceding character any time
(Greedy mode)
AB, AAB, ACB, ADB, AMNB
A*b
A.*b
. * Any character of any length
\? Match the characters in front of it 1 or 0 times
\{m,n\} matches the preceding characters at least m times, up to N times
grep ' A\{1,3\}b ' test.txt
Ab
AaB
grep ' A.\{1,3\}b ' test.txt
Location anchoring:
^ The beginning of the anchor line, the character after the anchor must appear at the beginning of the line
grep ' ^r. T '/etc/passwd
$ Anchor Line end, the character before the anchor must appear at the end of the row
grep ' B. h$ '/etc/passwd
^$ Blank Line
grep ' ^$ '/etc/inittab
\< or \b Anchor Word, any subsequent character must appear as the first word
\> or \b Anchors the ending, any character before it must appear as the tail of the word
\<root\>
Group:
\ (\) to group content
\ (ab\) *
Back to reference
\1 refers to the first opening parenthesis and the corresponding closing parenthesis that contain the contents of the
grep ' \ (1..e\). *\1 ' Test.txt
grep ' \ ([0-9]\). *\1$ '/etc/inittab line appears with numbers that have the same end of data
Extended Regular Expressions: (and general regular expressions differ in many places without adding \)
-e using extended regular expressions
Character Matching:
.
[]
[^]
Number of matches:
*:
?:
+: Match the characters in front of it at least once
? and + equals *
{M,n}
Group:
()
Or
|
C|cat C or Cat
(C|C) at cat or cat
Linux Learning Record-grep-egrep-is being expressed