Shell base SED usage

Source: Internet
Author: User
Tags first string

SED: Line processing command, default does not modify the original file, only the data in the pattern space to do processing, after processing, the mode space to print to the screen

sed [options] ' addresscommand ' file ...

-N: Silent mode, content not in the default display mode space

-I: Modify the original file directly

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

-f/path/to/sed_script

-R: Using extended regular expressions


Command

D: Delete rows that match the criteria

P: Show rows that match the criteria

A \string: Adds a new line before the specified line, the content string

\ n: can be used for line wrapping

I \string: Adds a new line after the specified line, the content 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/: Find and Replace, default replaces only the first string in each line that is matched to the pattern

Sed ' s/^//#/'/etc/fstab

Modifier:

G: Global Substitution

Sed ' s/\//#/g '/etc/fstab

I: Ignore character case

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

&: Reference pattern matching

Address

1,startline,endline

Like 1,100.

$: Last line

2,/regexp/Regular Expressions

/^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;



History | Sed ' s#[[:space]] '

This article is from the "Time and Space" blog, please be sure to keep this source http://tccsl.blog.51cto.com/4387692/1621949

Shell base SED usage

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.