Directory:
Basic operation of 1.sed, mode space, advanced operation
What is one.1 sed?
Streaming editor, the text content line-wise, you can copy, delete, modify the file
ONE.2 sed format
Sed-n '/^for/p '/etc/passwd lists the lines in the/etc/passwd file for the start
Sed-n ' 5,8p ' file Find file 5th row-N Mask Default output
' 5p;8p ' shows 5th, 8th line
' 4,+10p ' line 4th, and the following 10 lines
How many lines of ' $= ' statistical files can be judged by numbers
'/Regular/P ' regular match
Sed-n ' 2,4!p '/etc/passwd print/etc/passwd lines outside of 2 lines and 4 lines,! Take counter
d Delete (original file unchanged) P view C line modification S keyword modification I actually make changes
Sed ' $d ' to delete the last line
Sed '/^$/d ' to delete blank lines
Sed ' 3c xxx ' file replacement
Sed ' s/old/new/g ' substitution g can be equal to 2 replace 2nd, default 1
Sed ' s/old//' delete keywords
Sed ' s/^ #an/an/' to annotate
ONE.2 Output Text:
One.3 Deleting text
One.4 replacing text
Sed ' s,old,new, ' s after substitution symbol casual
Sed ' s/doc/&s/g ' & equals doc
Generic: (ABC) duplicates the contents of parentheses, can be multiple
Use: \1 First
Sed-r ' s/a (BC)/\1s/'-R support Extensions
Sed-r ' s,^ (.) (.*) (.) $,\3\2\1, '/etc/passwd a character reversal before and after
Sed-n ' p;n ' file odd line n is read Next line
Sed-n ' n;p ' even lines
one.5 Example
Modify IP in File
Two.1 Text block processing
two.2 Example
\ n or \ To break the line
THREE.1 file Import and Export
THREE.2 mode space and hold space
Basic action
Liezi
Four.1 statement
Most of the above content from Dahne PPT resources, here for collection and collation!
The SED of Linux