In Linux, you can use the sed command to replace the file content. This command is used to use scripts to process text files. When the parameter is set to "-i", you can replace the specified file content. The syntax is " sed -i 's/replaced content/content to be replaced/' file name".
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
To replace the content of a file
sed -i 's/被替换的内容/要替换成的内容/' file
##Expand knowledge :
If you want to replace the content of a file, copy it first and then replace it to avoid replacement errorssed 's/被替换的内容/要替换成的内容/g' file > file.out mv file.out file
sed -i "s/要找查找的文本/替换后的文本/g" `grep -rl "要找查找的文本" ./`
sed -i "s/要找查找的文本/替换后的文本/g" `grep -rl "要找查找的文本" /任意文件夹`
##Related recommendations:《
Linux video tutorialThe above is the detailed content of How to replace file content in linux. For more information, please follow other related articles on the PHP Chinese website!