The Linux sed command uses script to process text files
SED can process and edit text files according to script instructions.
SED is mainly used to automatically edit one or more files, to simplify the repeated operation of the file, to write the conversion program, etc.
Grammar
sed [-hnv][-e<script>][-f<script file >][text file]
Parameter description:
-e<script> or--expression=<script> processes the input text file with the script specified in the options.
-f<script file > or--file=<script file > process the input text file with the script file specified in the options.
-h or--help display Help.
-N or--quiet or--silent only show results after script processing.
-V or--version displays version information.
Action Description:
A: New, a can be followed by a string, and these strings will appear on a new line (the next line)
C: Replace, C can be followed by a string, these strings can replace the line between N1,N2
D: Delete, because it is deleted ah, so D usually does not take anything after
I: Insert, I can be followed by a string, and these strings will appear on a new line (the current line)
P: print, i.e. print a selected data, usually p will run with parameter sed-n
S: Replace, can be directly replaced by the work, usually this s action can be paired with the formal notation
Address delimitation:
1) do not give address: the full text of the processing
2) Single Address:
#: Specified line, $: last line
/pattern/: Each row to which the pattern can be matched
3) address range:
#,#
#,+#
/pat1/,/pat2/
#,/pat1/
4) ~: Step forward
Odd lines
2~2 even rows
Examples of sed:
Sed-n ' 2,/root/p '/etc/passwd starting from 2 lines
Sed-n '/^$/= ' file displays empty line line numbers
Sed '/root/a\superman '/etc/passwd after line
Sed '/root/i\superman '/etc/passwd before line
Sed '/root/c\superman '/etc/passwd instead of line
The SED usage of LINUX