Sed(Stream Editor) Introduction
Sed is a stream editor. It is a pipeline command. It processes text files in the unit of action and can replace, delete, add, and select data; sed does not process text files, but readsMode Space(Memory), and then complete the editing in the mode space, output the editing result to the screen, and then process the next line, repeated operations until the end of the file.
Mode Space: Place the read content in one area of the memory for editing. These memory spaces are called mode spaces.
Format:
Sed [Options] 'address command' file...
Common options:
-I: directly modify the source file (use with caution)
-R: use an extended regular expression. The default value is a basic regular expression.
-N: silent display. By default, sed lists stdin data on the screen. After-N is used, only processed rows are displayed.
-E: execute multiple commands at the same time;-e 'COMMAND'
-F: Specifies a sed script file;-f filename
Address demarcation:
1. Startline and endline: Start row to end row to be processed
$: Indicates the last row.
2./RegEx/: match with a regular expression.
3./pattern1/,/pattern2/: the first row matched by pattern to the second row matched by Pattern
4. line number: the specified row.
5. Startline + #: Start from Startline and end with # Rows
Common commands:
D: delete rows that meet the conditions.
P: displays rows that meet the conditions.
A: append a new row to the end of the specified row.
A \ string: String indicates the content of a new line.
\ N: newline
I: append a new row before the specified row; I \ string
R: add the content of the specified file to the end of the line; r filename
W: Save the rows within the specified address range as the specified file; W filename
S: search and replace. By default, the string that is matched for the first time in each line is replaced.
S/pattern/string/(// can be replaced by other symbols ,###,@@@...)
G: indicates global replacement; S/prttern/string/g
I: case insensitive
&: You can use back-reference to reference the entire string that matches the pattern.
This article is from the "pole boy" blog, please be sure to keep this source http://wtime.blog.51cto.com/8829658/1537215