如何做到多文件查找并从unix提示符中进行替换 [英] How to do Multi file find and replace from unix prompt
本文介绍了如何做到多文件查找并从unix提示符中进行替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用包含子文件夹的目录中的每个文件(例如1.1.1.1)替换localhost,另外我希望它记录更改的文件名。我很难做到这一点,我应该使用什么命令?
grep -r --files-with-matches localhost * | tee changed_files | xargs sed -i's / localhost / 1.1.1.1 / g'更改的文件将记录到 changed_files
。
I want to replace 'localhost' with an actual ip like '1.1.1.1' in every file in a directory including subfolders, plus I want it to log the filenames it changed. I'm having a difficult time doing this, what command should I use?
解决方案
grep -r --files-with-matches localhost *|tee changed_files|xargs sed -i 's/localhost/1.1.1.1/g'
The files changed will be logged to changed_files
.
这篇关于如何做到多文件查找并从unix提示符中进行替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文