Sed for simple operation of Linux commands

Source: Internet
Author: User

Sed

SED syntax format:

Sed[options] ' command ' file (s)

Sed common options:

-N: Only the line (or action) that has been specially processed by SED is listed.

-E: Combining multiple SED commands

-F: Perform sed action within filename

-r:sed's actions support the syntax of extended formal notation.

-I: Directly modifies the contents of the read file, not the screen output

Sed common commands:

A: Append sed ' a xxx ' file after each line append xxxx sed ' $a xxx ' file last line append

I: Insert the sed ' i xxx ' file before inserting xxx into each line

C: replace sed ' 2c xxx ' file second line with XXX instead

D: Delete sed '/^$/d ' file delete blank line sed ' 1,5d ' file delete 第1-5 line

S: replace sed ' s/pattern/replace_str/g ' file/g means that SED will replace each match, otherwise it is the first match

&: A string that marks a matching style and can use matched content when replacing a string

\1 or \ 2:1th or 2nd matching string

Application:

1, &: Tag a string that matches a style, you can use matched content when replacing a string

2, \1 or \ 2:1th or 2nd matched string, \ (pattern\) for matching substring, pattern is included in () with Slash escaped

3. Combine multiple SED commands with pipelines

Sed ' expression ' | Sed ' expression '

Sed ' expression;expressiong '

Sed-e ' expression '-e ' expression '

Sed for simple operation of Linux commands

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.