深度阅读

How to replace text in multiple files using Linux command line

作者
作者
2023年08月22日
更新时间
9.96 分钟
阅读时间
0
阅读量

To replace text in multiple files using Linux command line, you can use the sed command with -i option. Here’s an example command:

sed -i 's/string_to_replace/replacement_string/g' file1.txt file2.txt file3.txt

In the above command, replace string_to_replace with the text that you want to replace and replacement_string with the text that you want to replace it with. The g at the end of the command stands for global, which means that all occurrences of the string will be replaced, not just the first one. Replace file1.txt file2.txt file3.txt with the actual filenames that you want to modify.

You can also use wildcards to perform the same action on multiple files at once. For example:

sed -i 's/string_to_replace/replacement_string/g' *.txt

This will replace all instances of string_to_replace with replacement_string in all files with a .txt extension in the current directory.

I hope that helps! Let me know if you have further questions.

相关标签

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。