. Find the contents of a file in a batch, for example:
# grep-rn "Text to find".
2. Find and replace the contents of the file in bulk.
# sed-i "s/the text to find/replace text/g" ' Grep-rl "to find text"./'
other uses of SED are as follows:
1, delete the beginning of the space
Sed ' s/^[]*//g ' filename
Sed ' s/^ *//g ' filename
Sed ' s/^[[:space:]]*//g ' filename
2. Add new lines before and after lines
After line: sed ' s/pattern/&\n/g ' filename
Before line: sed ' s/pattern/\n&/g ' filename
& Representative Pattern
3. Use variable substitution (using double quotes)
Sed-e "s/$var 1/$var 2/g" filename
4. Insert text before the first line
Sed-i ' 1 i\ insert string ' filename
5, insert on the last line
Sed-i ' $ a\ insert string ' filename
6, insert before matching rows
Sed-i '/pattern/i insert string ' filename
7. Insert after matching line
Sed-i '/pattern/a insert string ' filename
8. Delete lines of empty text lines and spaces and the lines of # notes
Grep-v ^# FileName | Sed/^[[:space:]]*$/d | Sed/^$/d
Find Command
Find-name ' file name to find ' | Xargs perl-pi-e ' s| replaced string | replaced string |g '
#查找替换当前目录下包含字符串并进行替换
Find-name ' *.txt ' | Xargs perl-pi-e ' s| Wisdom Village | North Mountain |g '
#递归查找替换
Find. -type f-name ' *.html ' | Xargs perl-pi-e ' s| Wisdom Village | North Mountain |g '
#搜索目录LOG包含显示出来
Find./-name ' *log* '-type D
Find./-name ' *log* '-type d more
Of course, you can also use Linux vim bulk replacement
Replace only the current line:
Example
: s/xxx/yyy/g
, if you need to make all the substitutions:
Example
:%s/xxx/yyy/g
If you need to replace the specified section, you can enter visual mode with V, and then
Example
: s/xxx/yyy/g
Alternatively, you can specify the number of rows to replace the specified range:
Example
: 10,31s/xxx/yyy/g
If you need to display line number, under Vim
Example
: Set Nu
Suppress line number:
Example
: Set Nonu
: S/well/good/replaces the current line first good
: S/well/good/g replaces the current line all good
: N, $s/well/good/replaces the first n line to the top of each line in the last line good
: N, $s/well/good/g replaces the first n line to all the good in the last line of each line
N is a number, and if N is., it means starting from the current line to the last line
:%s/well/good/(equivalent to: g/well/s//good/) replaces the first good of each line
:%s/well/good/g (equivalent to: g/well/s//good/g) replaces all the good in each line
You can use # as a separator, in which the middle appears/is not a separator
: s#well/#good/# Replace the first well/of the current line as good/
:%s#/usr/bin#/bin#g can replace all the paths/usr/bin in the file with/bin