Sed:stream Editor for filtering and transforming text flow editor textbox
SED does not use the-I case, do not modify the source files, only the processing results are printed to the screen, using-I will be directly modified source files, is a dangerous practice, used in scripts to modify the configuration file, beginners do not recommend.
How to use sed:
Sed Range modified Print:
Direct Print File line fourth: Sed-n ' 4p ' path_to_file
Only delete the data from line fourth to the next row (including the next blank line) and print additional data: sed ' 4,/^$/d '/path_to_file
Data from line fourth to the next row is not printed (including the next blank line): Sed-n ' 4,/^$/!p '/path_to_file
Show only the fourth line to the next empty row of data (including the next blank line) do not delete only print these: sed ' 4,/^$/!d '/path_to_file
The first line that is matched by the pattern is started, and the line to the second pattern matches to the end of all rows in the middle:/pattern1/,/pattern2/
Sed parameters:
-N:--quiet,--silent: Silent mode no longer defaults to display the contents of the mode
-r:use extended Regular expressions in the script. Using an extended regular expression
SED replacement:
Sed-r ' s/regexp/replacement/g '/path_to_file:sed-r ' s/[[:space:]]+//g ' file removes whitespace from the beginning of the line
Sed search Merge instance: Cat/etc/inittab |sed-r ' s/^#//g;s/^[[:space:]]+//g;/^$/d ': Remove the # number at the beginning of the file Inittab file, the first white space character, and the blank line
SED modifies or removes a word in the range: Sed-i ' 2,3s/\<nameserver\>//g '/etc/resolv.conf:
Remove 2 to 3 rows of nameserver
sed modifier: g: Global substitution
I: Ignore character case
Sed back to Application:
Sed ' s#\ (pattern\) #\1xx#g ' file
sed other: A \string: Append a new line after the specified line, with the contents "string"
I \string: Adds a new line before the specified line, with the content "Srting"
Linux command-sed