The SED usage of LINUX

Source: Internet
Author: User

The Linux sed command uses script to process text files

SED can process and edit text files according to script instructions.

SED is mainly used to automatically edit one or more files, to simplify the repeated operation of the file, to write the conversion program, etc.


sed [-hnv][-e<script>][-f<script file >][text file]

Parameter description:

-e<script> or--expression=<script> processes the input text file with the script specified in the options.

-f<script file > or--file=<script file > process the input text file with the script file specified in the options.

-h or--help display Help.

-N or--quiet or--silent only show results after script processing.

-V or--version displays version information.

Action Description:

A: New, a can be followed by a string, and these strings will appear on a new line (the next line)

C: Replace, C can be followed by a string, these strings can replace the line between N1,N2

D: Delete, because it is deleted ah, so D usually does not take anything after

I: Insert, I can be followed by a string, and these strings will appear on a new line (the current line)

P: print, i.e. print a selected data, usually p will run with parameter sed-n

S: Replace, can be directly replaced by the work, usually this s action can be paired with the formal notation

Address delimitation:

1) do not give address: the full text of the processing

2) Single Address:

#: Specified line, $: last line

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

3) address range:





4) ~: Step forward

Odd lines

2~2 even rows

Examples of sed:

Sed-n ' 2,/root/p '/etc/passwd starting from 2 lines

Sed-n '/^$/= ' file displays empty line line numbers

Sed '/root/a\superman '/etc/passwd after line

Sed '/root/i\superman '/etc/passwd before line

Sed '/root/c\superman '/etc/passwd instead of line

The SED usage 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: 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.