SED learning [Reference reprint]

Source: Internet
Author: User

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]

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.