Linux text The sed of the Three Musketeers

Source: Internet
Author: User

Sed:stream Editor, line editors

Usage:

sed [option] ... ' Script ' Inputfile ...

Script

' Address command '

Common options:

-N: Do not output the contents of the mode to the screen

-e: Multi-point editing

-f/path/to/script_file: Reading the edit script from the specified file

-R: Supports the use of extended regular expressions

-I: In situ editing

Address delimitation:

(1) Not to address: The full text of the processing

(2) Single address:

#: The specified row

/pattern/: Each row to which the pattern can be matched

(3) Address range:

#,#

#,+#

/pat1/,/pat2/

#,/pat1/

(4) ~: Step forward

Edit command:

D: Delete

P: Display the contents of the mode space

A \text: Append text at the end of the line; Support for multiline append using \ n

I \text: inserting text in front of the line; Support for multi-row insertion using \ n

C \text: Replacing a line of behavior or multiple lines of text

W/path/to/somefile: Save the pattern space to match the line to the specified file

R/path/from/somefile: Reads the text of the specified file after the line that matches the line in the pattern space

=: Prints line numbers for lines in pattern space

!: Take a reverse condition

s///: Supports the use of other separators, [email protected]@@,s###

Replace tag:

G: In-line global substitution

P: Show the rows that were successfully replaced

W/path/to/somefile: Saves the result of the substitution success to the specified file


Advanced Editing Commands:

H: Overwrite the contents of the pattern space in the hold space

H: Append the contents of the pattern space to the hold space

G: Remove data from hold space to pattern space

G: Append content from hold space to mode space

x: Swap the content in the pattern space with the content in the hold space

N: Reads the next line of matching rows to the pattern space

N: Append the next line of matching rows to the mode space

D: Delete rows in the pattern space

D: Delete all rows in multi-line mode space


Sed-n ' N;p ' FILE: Show even rows

Sed ' 1! G;h;$!d ' file: Reverse display of the contents of files

Sed ' $! n;$! D ' file: Two lines after removing the file

Sed ' $!d ' file: Take out the last line of files

Sed ' G ' FILE

Sed '/^$/d; G ' FILE:

Sed ' n;d ' FILE: Show Odd lines

Sed-n ' 1! g;h; $p ' file: Reverse display of each row in a file

This article is from the "Ricky Technology Blog" blog, make sure to keep this source http://r1cky.blog.51cto.com/10646564/1773864

Linux text The sed of the Three Musketeers

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.