Sed command basic usage

Source: Internet
Author: User

Sed(Stream Editor) Introduction

Sed is a stream editor. It is a pipeline command. It processes text files in the unit of action and can replace, delete, add, and select data; sed does not process text files, but readsMode Space(Memory), and then complete the editing in the mode space, output the editing result to the screen, and then process the next line, repeated operations until the end of the file.

Mode Space: Place the read content in one area of the memory for editing. These memory spaces are called mode spaces.

Format:

Sed [Options] 'address command' file...

Common options:

-I: directly modify the source file (use with caution)

-R: use an extended regular expression. The default value is a basic regular expression.

-N: silent display. By default, sed lists stdin data on the screen. After-N is used, only processed rows are displayed.

-E: execute multiple commands at the same time;-e 'COMMAND'

-F: Specifies a sed script file;-f filename

Address demarcation:

1. Startline and endline: Start row to end row to be processed

$: Indicates the last row.

2./RegEx/: match with a regular expression.

3./pattern1/,/pattern2/: the first row matched by pattern to the second row matched by Pattern

4. line number: the specified row.

5. Startline + #: Start from Startline and end with # Rows

Common commands:

D: delete rows that meet the conditions.

P: displays rows that meet the conditions.

A: append a new row to the end of the specified row.

A \ string: String indicates the content of a new line.

\ N: newline

I: append a new row before the specified row; I \ string

R: add the content of the specified file to the end of the line; r filename

W: Save the rows within the specified address range as the specified file; W filename

S: search and replace. By default, the string that is matched for the first time in each line is replaced.

S/pattern/string/(// can be replaced by other symbols ,###,@@@...)

G: indicates global replacement; S/prttern/string/g

I: case insensitive

&: You can use back-reference to reference the entire string that matches the pattern.

This article is from the "pole boy" blog, please be sure to keep this source http://wtime.blog.51cto.com/8829658/1537215

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.