Egrep
An extended regular expression implementation is similar to the grep text filtering feature: Grep-e grep [OPTIONS] PATTERN [FILE ...] grep [OPTIONS] [-E PATTERN |-f file] [FILE ...] Options:--color=auto: Shading The matched text after highlighting:-i:ignorecase, ignoring the case of the character:-O: Displays only the string that matches to itself:-V,--invert-match: explicit A line that cannot be matched to a pattern:-E,--extended-regexp: supports the use of extended regular expression metacharacters:-Q,--quiet,--silent: Silent mode, which does not output any information-G, supports basic regular expressions -a#:after, after # line-b#: Before, Front # row-c#:context, front and back # line extension Regular expression metacharacters: Character match:.: any single character []: A single character in the specified range [^]: The number of individual characters outside the specified range matches: *: Any time, 0,1 or multiple times?: 0 Or 1 times, its first character is optional +: its preceding character at least 1 times {m}: the character before the period m {m,n}: At least m times, up to n times {0,n} {m,} position anchoring: ^: Beginning of Line anchoring: $: Row End anchoring: \< \b: The first anchor \>,\b: The ending anchoring: grouping and Referencing: (): grouping; the characters that match the pattern in parentheses are recorded hermetical the internal variables of the expression engine; a forward reference: \1,\2 .... Or: A|b:a or B; c|cat:c or cat (c| C) Cat:cat or cat example: 1. Displays lines in the/etc/passwd file that do not end with/bin/bash: ~] #egrep-V "/bin.bash"/etc/passwd 2. Find the two-digit or three-digit number in the/etc/passwd file; ~] #egrep "\<[0-9]{2,3}\>" 3. Locate the/etc/rc.d/rc.sysinit or/etc/grub2.cfg. The line that starts with at least one white-space character in the file, followed by a non-whitespace character: ~] #egrep "^[[:space:]]+[^[:spac E:]] "/etc/grub2.cfg 4. Find an example of a line that ends with ' LISTEN ' followed by 0,1 or more white space characters in the ' Netstat-tan ' command: 1. Locate the/proc/meminfo file, all Lines beginning with uppercase or lowercase s; at least three implementations; (1) ~] #grep "^[ss" "/proc/meminfo (2) ~] #gre P-i "^[s]"/proc/meminfo (3) ~] #egrep "^ (s| S) "/proc/meminfo 2. Displays information about root, CentOS, or User1 users on the current system; ~] #grep-E" ^ (root|centos|user1) \> "/etc/pa SSWD 3. Find the line with a parenthesis followed by a word in the/etc/rc.d/init.d/functions file; ~] #grep-e-o "_[[:alnum:]]+\ (\)"/etc/rc.d/in It.d/functions 4. Use the EHCO command to output an absolute path, use Egrep to remove its base name; ~] #echo/etc/sysconfig | GREP-E-O "[^/]+/?$" further: Take out its pathname: similar to the result of executing dirname on it: 5. Find the value between 1-255 in the ifconfig command result; ~] #i Fconfig | GREP-E-O "\< ([1-9]|[ 1-9][0-9]|1[0-9]{2}|2[0-9][0-9]|25[0-5]) \> "6. Add user Bash,testbash,basher and Nologin (whose shell is/sbin/nologin; then find/et The line for the shell name of the user with the same name in the c/passwd file: ~] #grep-E "^ ([^:]+\>.*\1$]/etc/passwd 7. Find the Ifconfig command knot The IP address in the fruit; ~]fconfig | grep ' [0-9]\{1,3\}\. [0-9]\{1,3\}\. [0-9]\{1,3\}\. [0-9]\{1,3\} '
Extended Regular expression for Linux (Egrep)