This chapter focuses on the use of SED commands
Sed (stream editor) is a stream editor, or line editor, that is edited in the behavioral unit, and the VI editor that follows is a full-screen editor.
How SED works:
reads each row in the file line by row and places it in memory space, processes the data in the memory space, and prints the processed results to the screen. This memory space is also called pattern space.
The so-called pattern space: is put in the memory space of the data according to the pattern to match, matching the success of the data for the corresponding editing processing, the processed data to print to the screen .
Description: The SED command prints all the lines in the file to the screen by default.
The SED command does not modify the contents of the source file by default, but only produces the displayed effect.
Usage of the SED command:
sed [option] ' Addresscommand ' [FILE ...]
Option
-N: Silent mode, the SED command prints all the rows in the file by default, plus-n indicates that only rows that match the pattern are
Print to the screen to show it
-I: Modify the original file directly
-E script1-e SCRIPT2: Multiple scripts can be executed at the same time (the script here refers to ' Addresscommand ')
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/2E/E6/wKioL1OdkGWRXdQ9AAIDGrVczUA203.jpg "title=" E.png " alt= "Wkiol1odkgwrxdq9aaidgrvczua203.jpg"/>
-f/path/to/sed_script: This is a script file that holds the SED script commands, each line is a script, the command
This is done by loading each command in the script file to the command line, and then editing the line in the specified file that conforms to the pattern.
Using a method such as: Sed-f/path/to/sed_script FILE
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/2E/E5/wKiom1Odj-mgjJGhAAKxJ1la6Fc558.jpg "title="-f.png "alt=" Wkiom1odj-mgjjghaakxj1la6fc558.jpg "/>
-R: Indicates support for regular expressions
Address: Search for qualifying lines in a file
There are 5 types of address delimitation
1, designated Startline,endline
For example, lines 1th to 100th indicate: 1,100
2./regexp/: Use regular expressions in the pattern to locate
For example: To find a line starting with the root string, you can say:/^root/
3,/pattern1/,/pattern2/
Match: Starting with the first matching line from PATTERN1 to the end of the first matching line to pattern2, all rows in the middle
4. LineNumber: The first line specified
5, Startline,+n: Match from line StartLine, backward n line, matching n+1 line
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/2E/E5/wKiom1Odk7HzZYt4AACToBtALhw980.jpg "title=" W.png " alt= "Wkiom1odk7hzzyt4aactobtalhw980.jpg"/>
Command:
D: Delete the specified row
P: Show rows that match the criteria
A \string: Append a new row after the specified line, the contents of the new row are ' string '
I \string: Append a new line to the front of the specified line, the contents of the new row are ' string '
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/2E/E6/wKioL1OdluuhzDEKAAG5DL-dKL0994.jpg "title=" A.png " alt= "Wkiol1odluuhzdekaag5dl-dkl0994.jpg"/>
R: Add the specified file to the qualifying row
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/2E/E6/wKiom1OdmQLgvt-mAAGqm7QKdVU930.jpg "title=" R.png " alt= "Wkiom1odmqlgvt-maagqm7qkdvu930.jpg"/>
W: Save content in specified range to specified file
s/pattern/string/modifier: string substitution; Note: string is not allowed to use metacharacters because he is not a pattern
The default no modifier means that only the first match to the string in each row is replaced
G: Indicates global substitution
Description: The substitution is not limited to/to represent, #,@, etc. can be used to represent the substitution character
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/2E/E6/wKioL1OdmqazvaraAAPtLbZg3ik889.jpg "title=" S.png " alt= "Wkiol1odmqazvaraaaptlbzg3ik889.jpg"/>
&: Only the entire string of pattern matching can be referenced
Back reference: You can refer to the string you want to reference, either all or part