1, vi Edit the string in the replacement file
: S/nice/good/replaces the current line the first nice is good
: S/nice/good/g replaces the current line all nice is good
: N, $s/nice/good/replaces the first nice for each row in the beginning of the nth row to the last row good
: N, $s/nice/good/g replace the nth line to start with the last row in each row all nice is good
N is a number, if N is., indicating the beginning of the current line to the last row
:%s/nice/good/(equivalent to: g/nice/s//good/) replaces the first nice of each line as a good
:%s/nice/good/g (equivalent to: g/nice/s//good/g) replaces all nice in each row as good
You can use # as a delimiter, at which time the middle/not as a delimiter
: s#nice/#good/# Replace the current row the first nice/is good/
:%s#/usr/bin#/bin#g
Replace all the paths in the file with/usr/bin/bin
2. Sed-i bulk replacement of strings in files
Format: Sed-i "s/lookup field/replace field/g" ' grep lookup field-rl path '
Sed-i "s/oldstring/newstring/g" ' grep oldstring-rl yourdir '
For example: Replace the nice in all files under/home/ock as book
Sed-i "s/nice/book/g" ' grep nice-rl/home '
Exp:sed-i "s/shabi/$/g" ' grep shabi-rl./'
Replace the text "garden" in file 1.txt with "Mirgarden"
Sed-i "S/garden/mirgarden/g" 1.txt
Replace "garden" in all files in the current directory with "Mirgarden"
Sed-i "S/garden/mirgarden/g"
VI Edit string substitution and sed usage