1, grep program
Linux text processing Three Musketeers have under - grep sed awk
grep: filtering the lines tool (line by line matching)
sed: a line of text editor (line by line editor)
awk: report generator, output formatting do
grep
It contains three commands: grep egrep fgrep, which are used for line mode (pattern) matching
egrep = grep -E - Extended regular expressions to match
fgrep = fast grep - only the files matching the wildcard
grep default use regular expressions to match text
grep usage:
grep [option] ... PATTERN [filename]
a * - all files beginning with a
Common options of grep - option
-E support the use of extended regular expressions
-P use perl regular expression language search engine (positive every language expression engine is not the same, even sed grep awk regexp engine used is different)
-i ignore case
-v anti-election
-o output only matched content
--color = auto syntax coloring
-n Display line numbers
-w word match fixing
PATTERN - Regular Expressions
Role: through some special characters to represent a class character, and then to the front of the command to execute; if you use special characters meaning in itself, it needs \ escape
Review: file wildcard
*? Any single character [] Any one character in the range [^] negated
1. character matches
Any of a character (equivalent to file a wildcard?)
[] Any one of the characters in the range
[^] Negated
Character: Digital [: digit for:] letters and numbers [: alnum:] letter [: Alpha:] Uppercase [: Upper:] Lowercase [: Lower:] Special characters [: punct:] blank characters [: Space:]
2. The number of matches
* Matching the immediately preceding character zero to n times
\? Matching the immediately preceding character zero to 1
\ + Immediately preceding matching character 1 to n times
\ {M \} m times preceding matching character
\ {M, n \} matches the character preceding to n times m
\ {0, n \} Matches the preceding character 0 to n times
\ {M, \} matches the preceding character to numerous m
[0-2][]
3. The position of the anchor
^ Anchor of the line
$ Anchored end of the line
\ B anchor and anchor the first word word endings (\ b word is used in front of the first word anchor, the anchor is used in the back end of a word)
\> Anchor suffix
\ <Anchoring the first word
4. Packet
abc * abcccc abc we want as a whole
\ (\) Example: \ (abc \) * abcabcabc
** grouping characteristics: default. linux system will be developed for the grouping variable, variable representation of \ 1 \ 2 \ 3 ......
\ (Ab + \ (xy \) * \) wherein \ 1 = ab + \ (xy \) *, \ 2 = xy
Exercise:
1, a line / proc / meminfo file size s of the beginning of the species
grep -i "^s" /proc/meminfo
2, display
0-255.0-255.0-255.0-255