Text Processing Tools
Grep
Sed (stream editor)
awk (report text Generator)
Basic usage of SED
By default, the original file is not edited, only the data in the pattern space is processed.
Sed:stream EDitor
sed [options] ' addresscommand ' file ...
-N Silent mode does not display content in mode space
-I modify the original file
-E script-e script: Multiple footsteps can be specified at the same time
-F: Specify a script file
-r: Indicates the use of extended regular expressions
Address
1.startline,endline
Like 1,100.
2./regexp/
/^root/
3./pattern1/,/pattern2/
First time by Pattern1 match to and Line start, to first be pattern2 match to end
4.LineNumber
The specified row
$ represents the last line
5.startyline,+n
From startline onwards, n rows Backward
Command:
D: Delete rows that match the criteria
Sed ' 1,5d '/etc/fstab
Sed '/oot/d '/etc/fstab
Sed ' 1,+2d '/etc/fstab
Sed '/^\//d '/etc/fstab with ^ anchor header/need add \ Escape
P: Show rows that match the criteria
A \string: Appends a new line after the specified line. Content is string
Sed '/^\//a \ #hello world\n#helo,linux '/etc/fstab
I \string: Appends a new line before the specified line. Content is string
R file: Adds the contents of the specified file to the qualifying line
Sed ' 2r/etc/issue '/etc/fstab
Sed ' $r/etc/issue '/etc/fstab last line added
W File: Saves content in the specified range to the specified file
Sed '/oot/w/tmp/oot.txt '/etc/fstab
s/pattern/string/modifier: Find and Replace, default replaces only the first string in each line that is matched to the pattern
Add modifier
G: Indicates global substitution
I: Ignore character case
Sed ' s/^\//#/'/etc/fstab at the beginning of/replaced by #
Sed ' s/\//#/g '/etc/fstab All/replaced by #
Sed ' [email protected]/@#@g '/etc/fstab/delimiter can be delimited with other characters such as @
$ reference pattern matches to the string
History | Sed ' s#^[[:space:]]*# #g ' | Cut-d '-f1
echo "/ETC/RC.D" | Sed-r ' [email protected]^ (/.*/) [^/]+/[email Protected]\[email protected] ' parent directory of a file
Linux Learning record-sed