Sed command details

Source: Internet
Author: User
Tags line editor

Basic usage of SED

Send: Line Editor (Full Screen Editor: VI)

Sed mode space

By default, the source file is not edited, and only the data in the mode space is processed. After the processing, the screen of the mode space is printed.

 

Sed [Options] 'address' file...

-N: silent mode. Unmatched rows are no longer printed.

-I: directly modify the source file. Check whether the modification is correct before use.

-E script: You can execute multiple operations at the same time.

-F/path/sed_script:

-R: indicates using an extended regular expression.

Address

1. Startline endline

For example, 1,100

$: Last line

2./Regexp/

/^ Root/

3./pattern1/,/pattern2/

The first row matched by pattern1 starts and ends with the first row matched by pattern2.

4. linenumber

Specify row

5. Startline, + n

Start from Startline, N rows backward

Command:

D: delete rows that meet the criteria: sed '1, 2D '/etc/fstab delete 1 2 rows

P: Display qualified rows: sed '/root/P'/etc/fstab print rows containing Root

A \ string: append a new row to the specified row with the content of string

sed ‘/^\//a \#hello world \n#hello world‘ /etc/fstab

I \ string: Add a new line before the specified row with the content of string

R file: add the content of the specified file to a qualified row.

sed ‘2r /etc/issue‘ /etc/fstab     #

W file: Save the content within the specified range to another file.

sed ‘/oot/w /tmp/oot.txt‘ /etc/fstab

S/Patten/string/modifier: search for and replace. By default, the string first matched by the pattern in each line

Modifier

G: Global replacement

I: case insensitive

sed ‘s/oot/OOT/‘ /etc/fstab

&: The reference mode matches the entire string.


This article from the "openvpn building" blog, please be sure to keep this source http://lovesource.blog.51cto.com/1454821/1569790

Sed command details

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.