A. Regular Expressions:
Metacharacters is a character used to illustrate the meaning of a character expression, in short, a character used to describe a character.
The regular expression re (Regular expression) is a string of characters consisting of a string of character and metacharacters.
The primary function of regular expressions is text query and string manipulation, which can match a character or character set of text. In fact, the regular expression completes the filtering of the data, rejecting the data that is not satisfied with the regular expression definition, leaving the data that matches the regular expression.
1. Composition of regular expressions
(1). General characters: characters with no special meaning
(2). Special characters (meta characters): metacharacters, which have special meanings in regular expressions
2. The following common meta characters in regular expressions
(1). POSIX Bre and ere have meta characters:
\: Typically used to turn on or off special meanings of subsequent characters, such as \ (... \) with \{...\}
. : Matches any single character (except Nul)
*: Match any number or no single character before it, for example:. Represents any character, the. * matches any length of any character
^: matches the regular expression immediately following it, the BRE only has a special meaning at the beginning of the regular expression, and Ere has special meanings in any position
$: Matches the preceding regular expression, at the end of the string or line. The BRE has a special meaning only at the end of the regular expression, and Ere has a special meaning in any position
[]: Matches any one of the characters in the square brackets, where the hyphen (-) is used to refer to the range of consecutive characters; ^ symbol bitterness appears in the first position of the square brackets, then matches any character not in the list.
(2). Only characters in the POSIX Bre:
\{n,m\}: An interval expression that matches the number of occurrences of a single character before it. \{n\} refers to reproducing n times; \{n,m\} refers to reproducing N to M times;
\ (\): Reserve space to store up to 9 independent sub-patterns in a single pattern. such as \ (ab\). *\1: Refers to two occurrences of a matched AB combination, with any number of characters in the middle.
\ n: Repeats the pattern in the \ (and \) square brackets in the nth child mode to this point.
(3). POSIX ere the characters are:
{n,m}: Same as \{n,m\} of Bre
+: One or more extensions that match the preceding regular expression
? : matches 0 or one extension of the preceding regular expression
| : matches the regular expression before or after the | symbol
(): Matches the regular expression group enclosed in square brackets.
(4). square brackets ([]) expressions
4.1. Character set [::]
Identifies the character set in the following ways:
[::alnum]: Numeric characters |
[:p UNCT:]: Punctuation character |
[: Alpha:]: Alphabetic character |
[: Graph:]: non-whitespace character |
[: Space:]: space character |
[: Blank:]: spaces and positional characters |
[: Lower:]: Lowercase alphabetic characters |
[: Upper:]: Uppercase characters |
[:cntrl:]: Control character |
[:xdigit:]: 16 binary number |
Two. Wildcard characters
The bash shell itself does not support regular expressions, and the use of regular expressions is shell commands and tools, such as Grep,sed,awk.
Bash Shell enables wildcard (Globbing) functionality with some metacharacters in regular expressions.
A wildcard is the process of storing a batch of specific file names stored on a computer, server, or network with a non-specific file name that contains wildcards. ( you can see that the wildcard is primarily applied to the matching file name, while the regular is mainly used on the string )
*-wildcards, which represent any character (0 to more)
? -wildcards, which represent one character
#-Notes
/-Jump symbol to restore special characters or wildcards to a general symbol
| -demarcation of two pipeline commands
; -Definition of continuity order
~-User's root directory
$-Variable value to be added before the variable
! -"Non" (not) in logical operation
/-Path Separator symbol
>>-Output guidance, respectively, "replace" and "accumulate"
'-single quote, no variable substitution function
"-double quotes with variable displacement function
'-quote symbol, two ' in the middle is a command that can be executed first
()-Middle is the beginning and end of the child shell
[]-Middle is a character combination
{}-middle command block combination
CTRL + C-terminates the current command
Ctrl+d-Input End (EOF), such as when the message ends
Ctrl+m-Just enter
Ctrl+s-Pause the output of the screen
CTRL+Q-Restore the output of the screen
Ctrl+u-at the prompt, delete the entire line of command
CTRL + Z-Pause current command
&&-Execution of a command after a successful execution of the current instruction
|| -When the execution of the current instruction fails, the following command is executed
Three. IO redirection
Standard output and standard error output are often used when we set up timed tasks. This is a very important concept in Linux, and this is very useful. The program should have the source side of the database, the destination of the data, and where the problem is reported, which are called standard input, standard output, and standard error output.
Redirection and piping
The shell provides several syntax to modify the default IO source and destination, which is where the standard input and output are.
< |
Modify standard input |
Sort < Ucid.txt |
By default, standard input is terminal and can be changed to where you want it |
<< |
|
Command << Delimiter |
Read in from standard input until you encounter the delimiter separator |
> |
modifying standard output |
Ls-l > Listinfo.txt |
By default, the standard output is the terminal, where the default output can be modified at this time. For example, the contents of the standard output can be written in a file. If the file already exists, it will be overwritten. |
>> |
Output attachments to a file |
Ls-l >> Listinfo.txt |
Unlike [;], [] The original content is emptied, and [>>] just appends the standard output to the end of the file. |
| |
Build Pipelines |
program1 | Program2 |
1. The standard output of the PROGRAM1 is the standard input of the PROGRAM2; 2. The efficiency of pipelines is at least one order of magnitude higher than the procedures for the use of temporary documents; |
File descriptor
In timed tasks, we often like to do this when redirecting.
1 * * */home/weiyg/crontab/clear_logs.sh >/dev/null 2>&1
What does the 2>&1 behind it mean, Here we understand the concept of file descriptors and binding redirects.
file |
file descriptor |
tr>
input file--standard input |
0 (the default is the terminal (which is said to be the default keyboard on the Internet) |
output file--standard output |
1 (default is terminal) |
error output file--standard error |
2 (default is terminal) |
Binding redirection
Commond >&m |
Standard output redirected to file descriptor M |
Command <&- |
Turn off standard input |
Command 0>&- |
Turn off standard output |
This article from the "Technology life, Simple not simple" blog, please be sure to keep this source http://willis.blog.51cto.com/11907152/1846590
shell--wildcard character, io redirection, regular expression