linuxday10--Text Processing tool SED

Source: Internet
Author: User

sed( Stream editor), line editors

sed [option]: ' Scrip ' Inputfile

Scrip ' Address command '

Do not give address: the full text of the processing

Single Address:

#: Specified line $: last row

/pattern/: Each row that can be matched by this pattern

Address range

#,#

#,+#

/part/,/part2/

#,/part1/

~: Step forward

Odd lines

2~2 even rows

Common options:

-N Close Printed content

-R using extended regular expressions

-e Multi-point editing

-I bak: Backing up files and editing them in situ

-R supports the use of extended regular expressions

Edit command:

d Delete matching rows for spatial pattern

P Print Current Space content

D Delete

! Pattern Match Inversion

= Pattern Space Line Plus line number

A[\]text: Append text after the specified line

Support for multi-line append using \ n

I[\]text: Inserting text in front of a row

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

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

R/path/somefile: Reads the text from the specified file to the line in the pattern space

=: Prints line numbers for lines in pattern space

! : Matching row inversion in pattern space

SED tools

s///: Find replacement, support using other separators, [email protected]@@,s###

Replace tag:

G: In-line global substitution

P: Show the rows that were successfully replaced

W/path/tosomefile: Saving a successful replacement row to a file

Advanced editing commands

P: Print mode space start to \ n content, and append to default output

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: Overlay content in the hold space into the pattern space

G: Append the contents of the hold space to the mode space

X swap the content in the pattern space with the content in the hold space

n overwrites the next line of the row that matches the read to the pattern space

N reads the next line of the matched row to append to the

D Delete rows in the pattern space

D: If the pattern space contains a newline character, the text in the pattern space until the first line break is deleted, and the new input line is not read, and the loop is restarted using the pattern space of the composition. If the pattern space does not contain a newline character, the normal new loop is started as if the D command was emitted

linuxday10--Text Processing tool SED

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.