Text Processing Edit command SED
Command format:
sed [option] ' (intercepted line) [action] ' file name
Option:-N: Only the rows that have been processed by SED are output
-e: Allow more than one action to be entered
-i:sed the modified result to the file
Intercept line: (1) Enter line number directly
(2)/Regular expression/
(3) x, y lines, or a regular replacement
(4) x,y! Reverse
(5) X~y starting from X line, step y line
(6) $ document at the end
Action: P print eg:sed-n ' (line) p ' student.txt
Add a new line after line A, add a new line before the I line
Sed ' 1,5a ============= ' student.txt
Sed '/regular//============ ' Student.txt
D Delete a row
Sed '/regular/d ' student.txt
Sed ' 4d ' student.txt
C replaces the specified line
Sed ' 2c canglaoshi bujigee ' Student.txt
Sed '/regular/C Lalalalalalala ' Student.txt
s replaces the specified string (replaces the first one in each line), and the end G indicates that each line
Sed '/Regular (anchor line)/s/regular (old)/ABCD (new)/' Student.txt
Sed ' s/regular (old)/ABCD (new)/' Student.txt (full text replacement)
Sed '/www/s/33/000/g ' zz_test.txt
Operation: {} Multiple command combinations, separated by;
Sed ' {1,20p;s/www/s/33/000//g} '
& Take the original character
Sed ' s/abc/&def ' student.txt (change ABC to ABCDEF)
U string first letter to uppercase
Sed ' s/abc/\u&/' student.txt (change ABC to ABC)
L Change the first letter of the string to lowercase
U string All letters are changed to uppercase
Sed ' s/abc/\u&/' student.txt (change ABC to ABC)
L string All letters are changed to lowercase
R inserts a file into the specified line of another file
Sed ' 1r abc.txt ' 123.txt (inserts the contents of Abc.txt into line 1th of the 123.txt file)
Q Exit SED
Sed '/false/q ' student.txt (Find a false to exit SED)
This article from "Sevenot" blog, reproduced please contact the author!
Linux Text Processing command "sed" simple solution