Two notes of confusion:
1) linux A regular expression is a unit of processing.
2) We used regular expressions and wildcards special characters are essentially different, for example: ls * .txt where * is a wildcard (indicates all), not a regular expression.
Note that character set issues:
To ensure that the character set: export LC_ALL = C
---------------------------------------------
Basic regular expressions + extended regular expression to explain the meaning:
---------------------------------------------
The representative and can represent any character (not including blank lines)
* Repeat any preceding zero or more characters
. * Matches all characters. (Including blank lines)
Sed -ri 'S # (. *) # \ 1 # G' bqh.txt
the results of the matches in the front of the main brackets, taken out after the manipulation \ 1.
^ Represents the beginning with what, ^ bqh begin with BQH
$ is what the end of
^ $ represent a blank line.
\ Examples \. To represent the point itself, the escape symbol, so that characters have special identity movement, took off his vest, to restore the prototype \ $
^. * To any number of characters at the beginning.
* $ To the end of any number of characters.
(. *) From the first character match, the stop space,
[ABC] matches any character within a character set [a-zA-Z]
[^ ABC] matches any character not included after ^; in parentheses the ^ is negated, and attention to ... the beginning of the distinction.
a \ {n, m \} repeated n to m times, before a repeat character. If Useful egrep / sed -r slash can be removed.
\ {n, \} repeated at least n times, a repeated character before. If Useful egrep / sed -r slash can be removed.
\ {n \} repeated n times, before a repeat character. If Useful egrep / sed -r slash can be removed.
① ^ word beginning with the search word; and vi ^ enough apart line
②word $ ending search word; and the beginning of a line VI $
③ ^ $ represents an empty line.
Extended regular expressions: ERP (egrep or grep -E)
+ Repeat one or more of the previous character
? Complex 0 or a 0 in front of the character
| Find multiple strings in line with or way
() to find out "user group" String
Practical example:
^ M m search begins with the
p $ Search to the end of p
^ $ Express empty number
Remove blank lines:grep –v “^$” bqh.log
View a blank line after the content removed:grep -vn “^$” bqh.log
Representative and can only represent any one character (not including blank lines)
Find characters with 0:
. * Matches all characters. (Including blank lines)
Look for the end of the character:
Wrong way: grep ". $" Bqh.log
The correct way:
grep “\.$” bqh.log
NOTE: \ represents only the point itself, the escape symbol, so that characters have special identity movement, took off his vest, to restore the prototype \ $
* * Example 1 was repeated one or more of the previous character.
grep -o "1 *" bqh.log // - o exact match
^. * Beginning with any number of characters.
* $ To the end of any number of characters.
Any one character in the set [abc] matches the character [a-zA-Z]
Match within any set of characters az a lowercase characters:
[^ ABC] matches any character not included after ^; ^ in parentheses is negated, and to pay attention to the difference between the beginning ...
Matches any non-numeric characters:
a \ {n, m \} repeated n to m times, before a repeat character. If Useful egrep / sed -r / grep -E slash can be removed.
\ {N, \} repeated at least n times, a repeated character before. If Useful egrep / sed -r slash can be removed.
\ {N \} repeated n times, before a repeat character. If Useful egrep / sed -r slash can be removed.
Note: egrep, grep -E or sed -r filter generally can not escape special characters. Multi-use parameters.
---------------------------------------------------------------------------------
Extended regular expressions: ERP (egrep or grep -E)
+ Repeating one or more of the foregoing character
? Complex 0 or a 0 in front of the character
| Find multiple strings in line with or way
() To find out "user group" String