6-2 sed command

Source: Internet
Author: User
Tags line editor

1. Sed:stream Editor, Stream editors

is to handle pure ASICC plain text, line-by-line manipulation.

There are two types of editor, line editor and full screen editor

SED: Default does not edit the original file, only the data in the pattern space to do processing, and then. After processing finishes, print the mode space to the screen.

2. Format: sed ' addresscommond ' file ...

Address:

1. Startline, Endline

For example: 1,100: from 1 to 100

2./pattern/is/regexp/

Like/^root/.

3./pattern1/,/pattern2/

From the first row that is matched to a pattern, to the end of the second line that is matched by the pattern, the middle row

4. linenumber

The specified row. Note, $ represents the last line.

5. Startline, +n

Starting from Startline, a few lines backwards

Command

D: Delete rows that match the criteria

First Kind

The second Kind

Third Kind

P: Show rows that match the criteria

A recurring display that meets the criteria, not one that meets the criteria.

The role of-n

A \string: Append a new line after the specified line

I usage, format I \string: Adds a new line before the specified line, with the contents of String

R file: Adds the specified file contents to the line that matches the criteria

W File: Saves content in the specified range to the specified file

S: Find and replace

The default is to replace only the string that matches the first companion pattern in each row

Format is: s/pattern/string/

Add modifier

Format: s/pattern/string/modifier

G: Global substitution.

I: Ignore case when finding

&: Reference pattern matches entire string

-I: Direct modification of the original file (dangerous)

-E script–e script: Multiple scripts can be executed at the same time

-f/path/to/sed. SCRIPT

sed–f/path/to/scripts file

-R: Using extensions

3. Practice

6-2 sed command

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.