Detailed usage of Oracle's SED command

Source: Internet
Author: User
Tags regular expression

1. Introduction

Sed is a non-interactive editor. It does not modify the file unless you use Shell redirection to save the results. By default, all output lines are printed to the screen.

The SED editor processes files (or inputs) line-by-row and sends the results to the screen. The process is as follows: First, SED saves the rows currently being processed in a temporary buffer (also known as the mode space) and then processes the rows in the temporary buffers and sends the line to the screen when it is finished. SED deletes it from the temporary buffer each time it finishes processing, and then reads the next line, processes and displays it. When the last line of the input file is processed, the SED ends. SED has a temporary buffer in each row and edits the copy, so the original file is not modified.

2. Addressable

The addressable is used to determine which rows to edit. The form of an address can be a number, a regular expression, or a combination of both. If no address is specified, SED processes all rows of the input file.

The address is a number, the line number is the "$" symbol, and the last line is represented. For example:

Sed-n ' 3p ' datafile

Print only the third line

Addresses are comma-delimited, the addresses that need to be processed are the ranges between the two lines, including these two lines. Scopes can be represented by numbers, regular expressions, or a combination of both. For example:

Sed ' 2,5d ' datafile

#删除第二到第五行

Sed '/my/,/you/d ' datafile

The line between the line #删除包含 "my" and the line that contains "you"

Sed '/my/,10d ' datafile

#删除包含 the contents of line to line tenth of "my"

3, Commands and options

The sed command tells SED how to handle each input line specified by the address, and if no address is specified, all input lines are processed.

(1) SED command

(2) SED option

Related Article

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.