Basic usage of SED
Sed:stream Editor
Line Editor
By default, the file content is not modified, only the data in the pattern space is processed, and after processing is finished, the pattern space is printed to the screen
sed [options] ' addresscommand ' file ...
-N: Silent mode, does not display the contents of the mode space
-I: Modify the original file directly
-E: Multiple scripts can be executed at the same time
-f/path/to/sed_script
Sed-f/path/to/scripts File
-R: Using extended regular expressions
D: Delete rows that match the criteria
P: Show rows that match the criteria
A:\string: Appends a new row after the specified row, with the contents of string
\ nthe line can be wrapped
I:\string: Adds a new row before the specified line, with the contents of string
R file: The contents of the specified file are added to the qualifying line
W File: The address specified in the range is saved to the specified file
s/pattern/string/: Find and Replace, default to only the first row in each row that is matched by the pattern
[Email protected] ~]# sed s/oot/oot//etc/fstab
s/pattern/string/g Global Substitution
I ignore character casing
@@@ ## # #通用
Delete the first two lines
Sed ' 1,2d '/tmp/text.txt
Delete First row and last row
Sed ' 1,$-1d '/tmp/text.txt
Delete one to last row
Sed ' 1, $d '/tmp/text.txt
Delete first three rows
Sed ' 1,+2d '/tmp/text.txt
Delete the specified line
[[Email protected] ~]# sed ' 2d '/tmp/text.txt
There's 8 in the delete row.
[[Email protected] ~]# sed '/8/d '/tmp/text.txt
----------
Print rows that match the criteria
Sed-n ' 1p '/tmp/test.txt
This article is from the "James Zhan Linux Advanced ops" blog, so be sure to keep this source http://jameszhan.blog.51cto.com/10980469/1875922
Linux Basic Article -14,sed command detailed