简体   繁体   English

Bash Shell中的文件编辑脚本

[英]Scripting of File Edits in a Bash Shell

I have a large directory structure with many files named "configuration.txt". 我有一个很大的目录结构,其中包含许多名为“ configuration.txt”的文件。 For each instance of configuration.txt that has directory "n10" somewhere in its path (and there are many such instances of this particular directory), I would like to do a search-and-replace where all instances of the string "DNSMax=20" gets replaced with string "DNSMax=50". 对于每个路径中都有目录“ n10”的configuration.txt实例(此特定目录有很多此类实例),我想进行搜索替换,其中所有字符串“ DNSMax = 20“被替换为字符串” DNSMax = 50“。

Please note that my path names contain spaces. 请注意,我的路径名包含空格。

Could someone please give a Bash shell script that, if invoked from the root of my large directory structure, would accomplish this task? 有人可以提供一个Bash shell脚本,如果从我的大型目录结构的根目录中调用该脚本,它将完成此任务?

I am using RedHat Linux. 我正在使用RedHat Linux。

Thank you! 谢谢!

Using find and GNU sed : 使用find和GNU sed

find / -path '*/n10/*' -name configuration.txt \
      -exec sed -i 's/DNSMax=20/DNSMax=50/' {} \;

如果完整文件路径之间没有空格,这将起作用。

find . -name "configuration.txt"|grep '\/n10\/'|xargs perl -pi -e 's/DNSMax=20/DNSMax=50/'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM