SED command:
Common scenarios:
1. Add content at the specified location
2. Delete the line where the specified character is located;
3. Replace the specified string with a new string;
4. Display only content that contains the specified characters
Answer:
-I: Indicates that modifications are persisted directly to the file
1.>sed-i '/test/a\one\ntwo ' test.txt//After the line where the test string exists, add one and then add a newline
Note: Without the G option, the default is to add eligible a\ to the following
Adding a line is automatically wrapped by default, and the last line does not add \ n
>sed-i ' #test_3 #a\two ' test.txt sed add mode, only support/as delimiter, the command does not take effect.
2.>sed-i '/\/$/d ' test.txt//delete the line with/to the end of the test.txt.
>sed-i '/two/d ' test.txt//delete the row containing the keyword
Note: For the removal mode of SED, only the/as delimiter is supported, and # characters are not supported as delimiters;
3.>sed-i ' s#test1#test2#g ' test.txt//test1 of each row in Test.txt is replaced with test2, g means there are multiple test1 in one row, all replaced with test2
> sed-i ' s/test1/test2/g ' test.txt//As delimiter, replace test1 with Test2
4.> sed-n '/test2/p ' test.txt//print only rows that contain test2
Linux command----SED