Home >Operation and Maintenance >Linux Operation and Maintenance >How to replace file content in linux

How to replace file content in linux

WBOY
WBOYOriginal
2022-04-07 17:43:0716309browse

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".

How to replace file content in linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How to replace the content of a file in Linux

To replace the content of a file

sed -i 's/被替换的内容/要替换成的内容/' file

How to replace file content in linux

##Expand knowledge :

If you want to replace the content of a file, copy it first and then replace it to avoid replacement errors

sed 's/被替换的内容/要替换成的内容/g' file > file.out
mv file.out file

Batch search and replace the content of the files in the current folder

sed -i "s/要找查找的文本/替换后的文本/g" `grep -rl "要找查找的文本" ./`

Batch search and replace file contents in any folder

sed -i "s/要找查找的文本/替换后的文本/g" `grep -rl "要找查找的文本" /任意文件夹`

How to replace file content in linux

How to replace file content in linux

How to replace file content in linux##Related recommendations:《

Linux video tutorial

The 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn