Linux command----SED

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.