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