SED is the Linux lightweight Flow editor, which is used for line operations, mainly for data selection, replacement, deletion, new, and so on.
Permissions: All Users
Location:/bin/sed
Usage: sed [-NEFR] [action] File
Parameters:
-N
When you do not add-N, both the data processed by the SED and the non-processed outputs, plus-n outputs only the rows of the SED operation
-E
Action editing of SED directly in command-line mode
For example: Sed-e ' s/aaa/b/g; s/aa/b/g ' file is also a multi-action operation, note the middle of the semicolon
- F
The SED action is written directly in a file, and the-F file can perform the SED action within the filename
-R
SED actions support extended regular expressions (default support for underlying regular expressions)
-I.
Directly modify the contents of the Read file
Action Description: [N1[,N2]] function
Not necessarily exist, generally represents the number of rows selected for the action, if the action is replaced between 5 and 15 rows, then "10,20c"
A new, the next line of the current row
SED ' 2a Hello World ' file output insert Hello World after line 2nd
Sed ' 2a Hello world\
My name is csdn ' file
the output inserts two lines below 2 lines, respectively, Hello World and my name is Scdn
pay special attention to the "\" Behind Hello World
C substitution, which is the whole line substitution
Sed ' 3,6c Hello csdn ' file
The output replaces only 3 to 6 rows with the Hello Csdn (the 3rd to 6th line has only one row of Hello Csdn, and not 3 to 6 lines each row is Hello Csdn)
D Delete
Sed ' 3,6d ' file output deletes content after 3 to 6 lines of file
I insert, the previous row of the current line
Similar to a action, refer to a action usage
P Printing
Sed-n ' 2,5p ' file prints line 2nd to 5th of file
S replacement
Sed ' s/oldstring/newstring/g ' file oldstring and newstring support basic regular expressions and extended regular expressions
Cat-n Nginx | Sed ' 1,99s/[0-9]\{1,\}\. [0-9]\{1,\}\. [0-9]\{1,\}\. [0-9]\{1,\}//g ' Replaces the first field IP address of the Nginx log from 1 to 99 lines with a null
The result is:
--[15/dec/2014:23:00:10 +0800],get/identified?key=this-is-tmp-apikey&digest= 914ebb2fd551844cbe15513c0126e6ee&digest-algorithm=ed2k&hash=9d37bb2988f26973371fab028feeeb93d5542300 & http/1.1,200,-, XMP Windows Client 4.9,-, ed2k://|file|ki141213.wmv|1119747351| 914ebb2fd551844cbe15513c0126e6ee|h,00e04c377725ng4e,ki141213.wmv,1119747351--[15/Dec/2014:23:00:10 +0800],GET /identified? http/1.1,401,-,-,-,-,-,-,---[15/dec/2014:23:00:10 +0800],get/identified? http/1.1,401,-,-,-,-,-,-,-94--[15/dec/2014:23:00:10 +0800],get/identified? http/1.1,401,-,-,-,-,-,-,----[15/dec/2014:23:00:10 +0800],-, 0,-,-,-,-,-,-,---[15/dec/2014:23:00:1 0 +0800],get/identified?key=this-is-tmp-apikey&digest=76bb7c854168dcd1bf15fcb92e4114ffd4cfe7de& digest-algorithm=magnet&hash=28003498535& http/1.1,200,-, Thunder Windows Client 7.9,-, Magnet:?xt=urn: BTIH:76BB7C854168DCD1BF15FCB92E4114FFD4CFE7DE,EC55F9E92A5212LQ,ABP-209R,1067178826--[15/dec/2014:23:00:10 +0800],get/identified? http/1.1,401,-,-,-,-,-,-,-98--[15/dec/2014:23:00:10 +0800],get/identified? http/1.1,401,-,-,-,-,-,-,----[15/dec/2014:23:00:10 +0800],-, 0,-,-,-,-,-,-,-100121.12.57.154--[15/dec /2014:23:00:10 +0800],get/identified? http/1.1,401,-,-,-,-,-,-,-
If the preceding command joins-I directly, the file is modified directly
The SED for linux commands