Function data |
Function |
: Label |
Create the locations where the commands in script. file are mutually tested. |
# |
Establish a solution |
{} |
A set of commands with the same IP address limit. |
! |
The number of rows. |
= |
Line number ). |
A/ |
Add the User Token. |
B label |
Jump the commands of the test line to the test position created. |
C/ |
Replace the data with the data imported by the user. |
D |
Divide the data. |
D |
Except the first newline letter/prefix in pattern space. |
G |
Copy the metadata from hold space. |
G |
Add data from hold space to pattern space. |
H |
Copy the metadata from pattern space to hold space. |
H |
Add information from pattern space to hold space. |
L |
Nonprinting character in the printed l data is printed using ASCII character. |
I/ |
Insert the data row that the user adds to the consumer. |
N |
Import the next item. |
N |
Add the next expected pattern space. |
P |
Print data. |
P |
Print the first newline letter/prefix in the pattern space. |
Q |
Jump out of SED sort failed. |
R |
Into its internal content. |
S |
Replace string. |
T label |
First, repeat the begin command for the slave node. If the slave node is converted into a cow P>, the slave node command jumps to the label node for the slave node. |
W |
Information is expected to be included in the website. |
X |
Intersection hold space and pattern space content. |
Y |
Transform character. |
Parameter number
Parameter number
This chapter describes the number of functions provided by all sed by using one function.
| S | d | A | I | c | p | L | r | w | Y |! | N | q | = | # | n | d | p | H | G | x | B | T |
In addition, in each region, the function of introducing the function of function data is described first, and then the format of function data matching the number of addresses is described, here, we also describe how sed reads the data of this function.
4.1 s
The number of bytes in the response (s) indicates the string in the substitute file. The command format is as follows:
[Address1 [,Address2]S/Pattern/Replacemen/[Flag]
The preceding format is described as follows:
- Function data s can be used with a maximum of two addresses.
- For details about "s/pattern/replacement/[flag]" (solution [12]), refer to the following annotations:
- Example:
The function D indicates the data deletion line. The command format is as follows:
[Address1 [,Address2]D
The preceding format is described as follows:
- Function D can work with up to two addresses.
- The following figure shows the dynamic conditions of SED statements:
- Divide the information that matches the number of addresses in the pattern space.
- Import the next item into pattern space.
- Repeat sed script.
- Example: Skip Section 3.3.
4.3
Function A indicates adding the information to the file. The command format is as follows:
[Address1]A/Information imported by the user
The preceding format is described as follows:
- Function A can work with a maximum of one address.
- The "/" character next to the function number A indicates the end of the row. The information imported by the user must be imported from the next line. If the data exceeds one row, you must add "/" at the end of each row "/".
- When the information in the pattern space is generated, sed follows the information that the user receives.
- Example:
- Topic: Add "Multi-job system" after the "Unix" string. The contents of input. dat defaults are as follows:
UNIX
- Description: use function a to add the imported data to the data row containing the "Unix" string.
- The SED command column is as follows:
Sed-e '/Unix/A/multi-industry systems' input. dat
After the preceding command is executed, the result is as follows:
UNIX multi-job system
4.4 I
The data volume I indicates that the data is inserted into the file. The command format is as follows:
[Address1]I/Information imported by the user
The preceding format is described as follows:
- Function I can work with a maximum of one address.
- The "/" character next to the function number I represents the end of the row. The information imported by the user must be imported from the next row. If the data exceeds one row, you must add "/" at the end of each row "/".
- The following figure shows how sed inserts an animation into a row: Before the information in pattern space is imported, sed first outputs the information that the user inputs.
- Example:
- Topic: Apply the article copyright to the Information row of the Central Research Institute, which is included in the input. dat documents, including "Dean: Li xiaozhe. The contents of the Input. dat file are as follows:
Dean: Li xiaozhe
- Description: using the function data, I used the article copyright to jump to the information bank of the Central Research Institute, which included "President Li xiaozhe.
- The SED command column is as follows:
Sed-e '/ Emy chief: Li xiaozhe/I/Article copyright at the Central Research Institute 'input. dat
After the preceding command is executed, the output is as follows:
Article copyright: Li xiaozhe, Chief of the Central Research Institute
4.5 c
Function C indicates the information in the change file. The format is as follows:
[Address1 [,Address2]C/Information imported by the user
The preceding format is described as follows:
- Function C can work with up to two addresses.
- The Function C character is followed by the "/" character to indicate the end of the line. The information that the user inputs must be imported from the next line. If the data exceeds one row, you must add "/" at the end of each row "/".
- Sed changes: when the information in pattern space is generated, sed changes it to the information imported by the user.
- Example: Example 2 and 3 of section 3.1.
4.6 P
The number of letters (p) indicates that the data is printed. The command format is as follows:
[Address1 [,Address2]P
The preceding format is described as follows:
- Function data P can work with up to two addresses.
- The following figure shows how sed copies a copy of pattern space to mark the output.
- Example: Internal content of section 3.4.
4.7 L
The number of letters (L). In addition to listing the nonprinting character in the information in ASCII notation, the value is equal to the number of letters (P. For example, Mark ^ [in input. dat values as ASCII characters.
The Great ^[ is a movie starring Steve McQueen.
After the sed-e 'l' input. dat command is executed, the result is as follows:
The Great /003 is a movie starring Steve McQueen.The Great is a movie starring Steve McQueen.
The second row above is expected to be sed's auto-generated (please refer to our solution [].
4.8 R
Function data R indicates that the data is stored in the file. The command format is as follows:
[Address1]RIts region name is anonymous.
The preceding format is described as follows:
- Function data R can work with a maximum of one address.
- In the instruction, there is only one space between the function data R and Its alias.
- The following figure shows the situation of SED internal operations: After the pattern space content is generated, sed releases its internal content and content. When it does not exist, sed tries to execute other commands without generating any warning messages.
- Example: Example 3 of section 3.1.
4.9 million
The number of letters is W, indicating that the file is stored in it. The command format is as follows:
[Address1 [,Address2]WIts region name is anonymous.
The preceding format is described as follows:
- The number of letters can work with up to two addresses.
- In the instruction, there is only one space between the number of letters w and its nickname.
- Sed sends the information about the action, for example, to upload the content in pattern space to it. When the data volume is imported, it will replace (overwrite) the original data in the case. In addition, when it does not exist, sed will re-generate it.
- Example 2: Skip section 3.1.
4.10 y
Letter Number y indicates the character in the Response item. The command format is as follows:
[Address1 [, Address2] y/Xyz.../ABC .../
The preceding format is described as follows:
- The function number can be used with a maximum of two addresses.
- In the command,/ABC.../xyz.../(X, Y, Z, a, B, c represents some characters) is the argument of Y. The characters ABC... And xyz... must be the same.
- Sed when the row is canceled, convert the character in pattern space to X, B to Y, and C to Z ....
- Example:
- Topic: change the "small letter" in the input. dat example to "large. The contents of input. dat defaults are as follows:
Sodd's Second Law: Sooner or later, the worst possible set of circumstances is bound to occur.
- Description: Use the letter number y to indicate sed as the letter size.
- The SED command column is as follows:
sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' input.dat
The result of running the above command is as follows:
SODD'S SECOND LAW: SOONER OR LATER, THE WORST POSSIBLE SET OF CIRCUMSTANCES IS BOUND TO OCCUR.
4.11!
Number of letters! This parameter indicates the number of rows that do not exist. When there are the following commands,
[Address1 [,Address2]!Function data
Indicates the number of rows that do not match the specified address. For example, in addition to the "1996" string and all the data rows, the following command is used to complete the operation:
sed -e '/1996/!d' input.dat
4.12 n
N indicates the next row of data. The command format is as follows:
[Address1 [,Address2]N
The preceding format is described as follows:
- The number of functions N can be used with a maximum of two addresses.
- The following figure shows the conditions when sed splits the row into the next row:
- Outputs the information in pattern space.
- Route the next item to pattern space.
- Indicates the next batch operation command.
- Examples (can be compared with the examples in [section4.18 ):
- Topic: outputs the data of the Input. dat dataset. The contents of the Input. dat file are as follows:
TheUNIXOperationSystem
- Description: On the command Column
- Grant the control right of the resource (subject to [section2.5]) to the command by selecting-n.
- Replace the data row (odd data row) in pattern space with the function data N ).
- Extract the data (even data) in pattern space using the function data p.
Finally, the entire batch shows only the even data in the original batch.
- The SED command column is as follows:
sed -n -e 'n' -e 'p' infro.dat
After the preceding command is executed, the result is as follows:
UNIXSystem
4.13 Q
Q indicates the SED hop. The command format is as follows:
[Address1]Q
The preceding format is described as follows:
- Function data Q can work with a maximum of one address.
- When sed performs a hop, it stops loading the pattern space data, and stops sending the data to the standard output data at the same time.
- Example:
Number of rows = indicates the number of rows of the printed data. The command format is as follows:
[Address1,[Address2]=
The preceding format is described as follows:
- Number of functions = the maximum number of two addresses.
- When a row is created, the row data is first exported before the row data is generated.
- Example:
4.15 #
In the script file, the text after the number of letters # Is an annotation. When the annotation text exceeds multiple lines, the lines must be separated.
N indicates that the next item is added to the pattern space. The command format is as follows:
[Address1,[Address2]N
The preceding format is described as follows:
- The number of functions N can be used with a maximum of two addresses.
- When sed completes a row, the next row of data is added to and added to the pattern space. The row length is separated by embedded newline character. In addition, when the parameter is replaced, the line character can be/N to match.
- Example:
- Topic: Merge the following two rows. The contents of input. dat are as follows:
The UNIXOperating System
- Description: Use the function data N to place the two rows in pattern space, in the use of the function data number S // N // separate the two rows of data;/N is replaced by a blank space, so that the two rows of data become one row of data.
- The SED command column is as follows:
sed -e 'N' -e 's//n/ /' input.dat
After the preceding command is executed, the result of the command output is as follows:
The UNIX Operating System
4.17 d
The number D indicates the first row of data in the pattern space. The command format is as follows:
[Address1,Address2]D
The preceding format is described as follows:
- Function D can be used with a maximum of two addresses.
- The comparison between function D and function D is as follows:
- When there is only one row in pattern space, D and D act the same.
- When there are multiple rows in pattern Space
- D indicates that only the first row of information in pattern space is deleted; D indicates that all rows are divided.
- D indicates that the next item is not added to the pattern space after the row is deleted, and the remaining item is re-written into the SED script; d. Write the SED script in the next row.
- Example: The second example in section 3.3.
4.18 P
The number of functions P indicates the first row of information in pattern space. The command format is as follows:
[Address1,Address2]P
The preceding format is described as follows:
- Function data P can be used with a maximum of two addresses.
- P and P are the same except for the data rows in the pattern space.
- Examples (can be used with examples in [section4.12 ):
- Topic: extract the odd data row in the input. dat file. The contents of the Input. dat file are as follows:
TheUNIXSystem
- Description: On the command Column
- Grant the control right of the resource (subject to [section2.5]) to the command by selecting-n.
- Add the even data row to the odd data row in pattern space using the function number n.
- Extract the first line (odd number row) in pattern space using the function data p.
After the odd data rows are displayed, the remaining data rows (even rows) in the pattern space are displayed. Finally, only the original odd data row information is displayed.
- Sed command column:
sed -n -e 'N' -e 'P' infro.dat
After the preceding command is executed, the result is as follows:
TheSystem
4.19 H
H indicates storing the information of pattern space to hold space. The command format is as follows:
[Address1,[Address2]H
The preceding format is described as follows:
- Function H can be used with a maximum of two addresses.
- When sed blocks row-based storage, the original data in the hold space is discarded.
- When all sed rows end, the hold space content is automatically cleared.
- Example: Skip section 3.4.
4.20 H
The only difference between function H and function H is that when sed reads row H, the data is overwritten to hold the original data in space, while H, the information is "add (append)" after the original information of hold space. For more information, see section 3.2.
4.21 GB
The function g indicates the action opposite to the function H. It indicates that the hold space content is put back into the pattern space. The command format is as follows:
[Address1,Address2]G
- The function g can be used with a maximum of two addresses.
- When SED was taken back to the action, the original data in pattern space was discarded (overwrite.
- Example: Skip section 3.4.
4.22 GB
The only difference between the function g and the function g is that when sed reads a row G, the original data in the pattern space (overwrite) is discarded, while G, the information is "add (append)" after the original information of pattern space. For example, refer to section 3.2 for example 1.
4.23 x
X indicates the information in the hold space and pattern space. The command format is as follows:
[Address1,[Address2]X
Function data x mostly works with the function data of other processing hold space. For example, replace 1st rows of data in input. dat bytes with 3rd rows of data. At this time, the function H and X are used together. Among them, the data is stored in the hold space with the function data h; when the 1st rows of data appear in pattern space, returns the content of the hold space and pattern space based on X. In this way, 3rd rows of data are replaced by 1st rows of data. The command column is as follows:
sed -e '1h' -e '3x' input.dat
4.24 B,: Label
Function number: the function of similar basic commands in sed script to function B. Here, the number of functions: Create a tag; the number of functions B refers to the Command Branch of the next line to the mark place line. Number of letters: matches with B in the script file as follows:
... Zookeeper command M1: Remember zookeeper command m2... [address1, [address2] B [remember]
When sed tries to [address1, [address2] B [remember] the command, for example, the information in pattern space matches the number of addresses, as a result, sed will branch the location of the next row to the mark set by: ([14, that is to say, the "commandid command m2 "... rows. In addition, if no message is recorded after the number B in the command, sed splits the next line of command branch to the end of the script file, this allows sed script to have a similar case statement structure in C statement.
Example:
- Topic: Re-print the start Letter of the input. dat row 40 times. The contents of input. dat defaults are as follows:
ABC
- Note: The following Code uses commands B P1 and P1 to construct a loop to add letters to a row. At the same time, 40 letters appear, it also uses command B to jump out of the circle. The following uses the first row of information "A" as an example to describe how to add 39 "a" to the same row in the example:
- Use the command S/A/AA/( 4.1 4.1) to convert "A" to "AA ".
- Construct a loop using commands B P1 and: P1, which aims to make the above-mentioned Dynamic Response line reversed. Every row in a circle, the "A" on the Data row will have one more. For example, the first cycle changes to AA, and the second cycle changes to aaa "....
- Use the command [ABC]/{40/}/B (Decoding [15]) as the condition for stopping the labeling. When the data row has 40 A records, the number of data records B jumps to the last row of the command to stop reading this row.
In the same way, the same way for other data rows.
- The SED command column is as follows:
sed -e '{:p1/A/s/A/AA//B/s/B/BB//C/s/C/CC//[ABC]/{40/}/bb p1}' input.dat
4.25 TB
Basically, the function of function T is similar to function B, except before the branch of function t, the replacement command before the replacement command is successfully executed. In the script file, the conditions are as follows:
... Please refer command M1: Remember please refer to command m2... S /... /... /[address1, [address2] T [] command m3
In this case, unlike function B, when function data is t branch, the previous replacement command is checked for success and No. If the command succeeds, branch is added. If the command fails, branch is not performed. If the command fails, the next batch operation is executed, for example, M3.
Example:
4.16 n 4.14 = 4.2 d