I. options and Parameters:
In the use of SED, all data from STDIN is generally listed on the terminal. But if you add-sedsed action;-R: TheAction of SED supports the syntax of extended formal notation. (The default is the basic formal notation of French)-I: Directly modifies the contents of the read file, not the output to the terminal.
Two. Function Description:
SED-1,20s/old/new/g!
Three. Example:
1.ll | Sed ' 2,5d ' lists folder contents and deletes 2–5 rows
2.ll | Sed ' 2d ' lists folder contents and deletes line 2nd
3.ll | Sed ' 2, $d ' lists the contents of the folder and deletes the second line to the last row
4.ll | SED ' 2a think time ' lists the contents of the folder and adds a "think Time" under the second line
5.ll | Sed ' 2i think time ' lists the contents of the folder and adds a "think Time" on the second line
6.ll | Sed ' 2i think time\ enter thinking ' again to list the contents of the folder, and add two lines on the second line, using \ to express multiple sentences
7.ll | Sed ' 2,5c think time ' lists the contents of the folder and replaces the 2–5 line with "Think Time"
8.ll | Sed-n ' 5,7p ' lists the contents of the 第5-7 line
9.ll | Sed-n '/web/p ' prints a line containing the web, and the regular is represented by//
10.ll | Sed '/web/d ' deletes rows containing the web, other rows output
11.ll | Sed-n '/web/{s/web_/testweb_/;p} ' find the row containing the web_, and replace the web_ with the testweb_,{} to indicate the expression to be executed, the statements in the inside are separated, the s/t/t1/g represents the substitution, and the G represents all, not the first.
12.ll | Sed-e ' 7, $d '-e ' s/admin/testadmin/g ' multipoint edit, means to delete the contents of the 7th line first, and then replace the rest of the content.
13.sed-i ' s/test/hello/g ' test.txt means to change all of the test in the test.txt directly to Hello, I use this operation with caution
14.sed-i ' $a helloend ' test.txt indicates that the last line of Test.txt is added with Helloend, $ means finally, can also use numbers, such as 2a, which means to increase under the second line
SED learning [Reference reprint]