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

How to replace file content in linux

WBOY
Release: 2022-04-07 17:43:07
Original
16306 people have browsed it

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
Copy after login

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
Copy after login

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

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

Batch search and replace file contents in any folder

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template