SED basic usage:
Sed:stream Editor Editor is in line editor (vi is Full screen editor)
SED: Mode space
Edit the original file by default, processing only the data in the pattern space
sed [options] ' Addresscommand ' FILE ...
Options
-N: Silent mode, no longer displays the contents of the mode space by default
-I: Modify the original file directly
-E script-e script: Multiple scripts can be executed at the same time
-F ScriptFile: Specifies the file where the script is stored
Sed-f/path/of/scripts FILE
-r: Indicates the use of extended regular expressions
Address:
1. startingline,endling with line numbers
1,100--From line 1th to line 100
$: Last line
2./regexp/---using regular expressions
/^root/---lines starting with Root
3./pattern1,pattern2/---from the first line that was matched by PATTERN1, to the end of the line that was first matched to the pattern2, all the rows in the middle
4. LineNumber---The specified row
5. StartLine, +n---starting from StartLine, N rows Backward, total n+1 rows
Command
D: Delete rows that match the criteria
P: Show rows that match the criteria
A \ "string": Appends a new line after the specified line with the contents "string"
I \string: Appends a new line to the specified line, with the contents "string"
R file: Adds the contents of the specified file to the qualifying line
W file: Saves the contents of the specified row to the specified file
s/pattern/string/: Find and Replace, default replaces only the first string in each row that is matched by the pattern
G: Global Substitution
I: Find is ignore character case
Note: s///<---> s### <---> [email protected]@@, separators can be represented using the same three symbols
\ (\), \1, \2
&: The string to which the reference pattern matches
Basic usage of SED