sed is a flow the encoders, which is in very text processing tool that perfect fit it with a regular expression, function thereof can be extraordinary.
Handling, storing the row currently being processed in a temporary buffer, called a "model space" (oattern space), then the processing contents of the buffer to see with sed command, into the post-processing, the contents of the buffer sent to the screen display.
Then the next line processing, so repeated until the end of the file. Change the content of the document did not change unless the command written content updates.
Addressing is used to determine which rows to edit. The address may be a digital form, a regular expression, or a combination of both. If the address is not specified, sed will process all the input file lines.
sed command function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
sed common command parameters
1 2 3 4 5 6 7 |
|
1 |
|
Frequently used commands show
sed good output line, with the source file:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Print only the third line
1 |
|
View files only line 3 to line 9
1 |
|
Filtering a specific character string, displaying the contents of the line n
1 |
|
Display comprising "hhh" row that contains the line between "omc" line
1 |
|
Print lines 1-5 and line numbers
1 |
|
Only the line number of the matched string
1 |
|
Print and sign matching rows behind and in accordance with [the equivalent of a keyword query]
1 |
|
Replace yum.log document root with the real world [written]
1 2 3 4 5 |
|
Print the last line
1 |
|
Add happy in the first line of the file, end of file add the new year
1 2 |
|
Hahaha added in each line of the file first and fourth rows below
1 |
|
& Symbol represents the result of the last match in the sed command
1 |
|
Delete the first 3 to line 9, just do not show it
1 |
|
Delete contains "hhh" line to include the line between "omc" row
1 |
|
Delete the contents included "omc" line to the tenth row
1 |
|
NOTE: In figures can be used, a regular expression, or a combination of both represent
5 to 10 show matching line in the root, the root of all the rows replaced FTL, and printed to the screen
1 2 |
|
-e is editing commands for multiple editing tasks
1 2 |
|
Print lines 3-6, and replace the matching shutdown reboot
1 |
|
-r命令是读命令。sed使用该命令将一个文本文件中的内容加到当前文件的特定位置上
1 2 |
|
-w是写入命令
1 2 3 |
|
打印1-5行,并显示行号
1 |
|
sed的正则匹配
正则匹配IP和子网掩码
1 2 3 4 |
|
配合find命令的使用
1 2 3 4 |
|
sed错误使用
1 2 |
|