The SED of Linux

Source: Internet
Author: User

Directory:

Basic operation of 1.sed, mode space, advanced operation

What is one.1 sed?

Streaming editor, the text content line-wise, you can copy, delete, modify the file

ONE.2 sed format

Sed-n '/^for/p '/etc/passwd lists the lines in the/etc/passwd file for the start

Sed-n ' 5,8p ' file Find file 5th row-N Mask Default output

' 5p;8p ' shows 5th, 8th line

' 4,+10p ' line 4th, and the following 10 lines

How many lines of ' $= ' statistical files can be judged by numbers

'/Regular/P ' regular match

Sed-n ' 2,4!p '/etc/passwd print/etc/passwd lines outside of 2 lines and 4 lines,! Take counter

d Delete (original file unchanged) P view C line modification S keyword modification I actually make changes

Sed ' $d ' to delete the last line

Sed '/^$/d ' to delete blank lines

Sed ' 3c xxx ' file replacement

Sed ' s/old/new/g ' substitution g can be equal to 2 replace 2nd, default 1

Sed ' s/old//' delete keywords

Sed ' s/^ #an/an/' to annotate

ONE.2 Output Text:

One.3 Deleting text

One.4 replacing text

Sed ' s,old,new, ' s after substitution symbol casual

Sed ' s/doc/&s/g ' & equals doc

Generic: (ABC) duplicates the contents of parentheses, can be multiple

Use: \1 First

Sed-r ' s/a (BC)/\1s/'-R support Extensions

Sed-r ' s,^ (.) (.*) (.) $,\3\2\1, '/etc/passwd a character reversal before and after

Sed-n ' p;n ' file odd line n is read Next line

Sed-n ' n;p ' even lines


one.5 Example

Modify IP in File

Two.1 Text block processing

two.2 Example

\ n or \ To break the line

THREE.1 file Import and Export

THREE.2 mode space and hold space

Basic action

Liezi

Four.1 statement

Most of the above content from Dahne PPT resources, here for collection and collation!

The SED of Linux

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.