Linux sed use

Source: Internet
Author: User

Sed:stream Editor (row editor)


SED: Mode space

By default, the original file is not edited, only the data in the pattern space is processed, and after the processing is finished, the pattern space is printed to the screen;


sed [options] ' addresscommand ' file ...

-N: Silent mode, no longer displays the contents of the mode space by default

-I: Modify the original file directly

-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: Indicates the use of extended regular expressions


Address:

1, Startline,endline

Like 1,100.

$: Last line

2,/regexp/

/^root/

3,/pattern1/,/pattern2/

The first line that is matched by the pattern1 begins at the end of the line that is first matched to the pattern2, and all the rows in the middle

4, LineNumber

The specified row

5, StartLine, +n

Starting from Startline, n rows backward;

Command:

D: Delete the qualifying line;

P: Displays rows that match the criteria;

A \string: Appends a new line after the specified line, with the contents of string

\ n: can be used for line wrapping

I \string: Adds a new row before the specified line, with the contents of string

R file: Adds the contents of the specified file to the qualifying line

W File: Save the row in the range specified by the address to the specified file;

s/pattern/string/modifier: Find and Replace, default replaces only the first string in each line that is matched to the pattern

Add modifier

G: Global Substitution

I: Ignore character case

s///: s###, [email protected]@@


This article is from the "rime" blog, please be sure to keep this source http://kinrey.blog.51cto.com/10492082/1838163

Linux sed use

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.