The grep command can find the contents of a single file or folder under a file. Use the parameter "R" or "R" to recursively find all the files under the specified folder; The parameter "L" lets the grep output the file name that contains the specified string, and immediately stops the query to the same file after the first match succeeds. If you do not use "l", grep queries a single file for all rows containing the specified string in the output file, and the folder query with the "file name: include string line" output.
With the knowledge mentioned above, the command to perform a bulk substitution can be written as:
grep "NETINGCN"-rl/assign-path | Xargs sed-i ' s/netingcn/www.netingcn/g '
Or
Sed-i ' s/netingcn/www.netingcn/g ' grep ' netingcn '-rl/assign-path '
There is also a more complicated way of writing:
grep "NETINGCN" *-r | Awk-f: ' {print $} ' | Sort | Uniq | Xargs sed-i ' s/netingcn/www.netingcn/g '
Where the command awk is used to split the string, uniq the result.
, information readily available on the web
Format: Sed-i "s/lookup field/replace field/g" ' grep lookup field-rl path '
Linux sed to bulk replace strings in multiple files
Sed-i "s/oldstring/newstring/g" ' grep oldstring-rl yourdir '
For example: Replace www.111cn.net in all files under/home as 111cn.net
Sed-i "s/www.111cn.net/111cn.net/g" ' grep www.111cn.net-rl/home '
Exp:sed-i "s/shabi/$/g" ' grep shabi-rl./'
2. Additional additional
2.1 Replace the text "garden" in the file 1.txt with "Mirgarden"
# sed-i "s/garden/mirgarden/g" 1.txt//sed-i is simple
2.2 Replace "garden" in all files in the current directory with "Mirgarden"
# # Sed-i "s/garden/mirgarden/g" ' ls '/In fact, LS out of multiple file names just