A, sed
sed is a stream editor that processes a row contents. When processing, the line currently being processed in a temporary storage
Buffer, referred to as "model space" (pattern space), followed by treatment with sed command buffer
Content, processing is complete, the contents of the buffer sent to the screen. Then reads the downlink, perform the next cycle.
If no special command so as 'D', that clears the pattern space between the two cycles, but will not clear
Empty space reserved. This is repeated until the end of the file. File contents not changed, unless you re-use
Directional memory output.
Function: mainly used to automatically edit one or more files, the file operation is repeated to simplify the preparation of the conversion procedures
Reference: http://www.gnu.org/software/sed/manual/sed.html
用法: sed [option]... 'script' inputfile...
Common options
-n do not output the contents of the pattern space to the screen, that does not automatically print
-e multi-point editing
-f / PATH / SCRIPT_FILE edit the script to read from the specified file
-r supports extended regular expressions
-i.bak backup file and place editing
Address defined
(1) not to address: the full text processing
(2) Single Address:
#: Specific line, $: The last line
/ Pattern /: where is can be matched to the pattern of each line
(3) Address range:
#,#
#,+#
/ Pat1 /, / pat2 /
# / Pat1 /
(4) ~: step
Odd rows 1-2
2 ~ sed tool even rows 2
replace
s /// Find Alternatively, other separators supports, s @@@, s ###
Replacement tags:
Alternatively the global row g
p Replace successful line display
Save w / PATH / FILE replaces the successful line to the file
Examples
sed ‘2p’ /etc/passwd
sed -n ‘2p’ /etc/passwd
sed -n ‘1,4p’ /etc/passwd
sed -n ‘/root/p’ /etc/passwd
sed -n '2, / root / p' / etc / passwd line starting from 2
sed -n '/ ^ $ / =' file air display line number
sed -n -it '/ ^ $ / p' -as '/ ^ $ / =' File
Sed '/ root / a \ superman' after the / etc / passwd line
sed '/ root / i \ superman' / etc / passwd front row
sed '/ root / c \ superman' / etc / passwd line instead of
But '/ ^ $ / d' file
sed ‘1,10d’ file
NL / etc / passwd | But '2,5d'
nl /etc/passwd | sed ‘2a tea’
sed 's/test/mytest/g' example
sed -n 's / root / & superman / p' / etc / passwd word after
sed -n 's / root / superman & / p' before the / etc / passwd word
sed -e ‘s/dog/cat/’ -e ‘s/hi/lo/’ pets
sed –i.bak ‘s/dog/cat/g’ pets
Senior Editor command
Prior to the beginning of the print pattern space \ n content, and added to the default output: P
h: the contents of the pattern space holding the cover to the space
H: the contents of the pattern space is added to the holding space
g: Remove the cover to the mode data from the space holding space
G: the additional content is removed from the holding space into model space
x: the contents of the pattern space holding the contents of the space are interchangeable
n: Reads the next line to the line matching the pattern space to cover
N: Reads the next line of the matched pattern space appended to row
d: Delete line in the pattern space
D: If the pattern space contain line breaks, then delete mode until the space of a line break in the text,
And will not read the new entry line, and the use of synthetic model space to restart the cycle. If the pattern space
Does not contain line breaks, it will be like a normal issue d command to start a new cycle as
To be continued. . . .