linux - 在 Bash Shell 中编写文件编辑脚本

标签 linux bash shell scripting redhat

我有一个很大的目录结构,其中包含许多名为“configuration.txt”的文件。对于在其路径中某处具有目录“n10”的 configuration.txt 的每个实例(并且该特定目录有许多这样的实例),我想进行搜索和替换,其中字符串“DNSMax = 的所有实例20"被替换为字符串 "DNSMax=50"。

请注意我的路径名包含空格。

谁能提供一个 Bash shell 脚本,如果从我的大型目录结构的根目录调用它,就能完成这个任务?

我正在使用 RedHat Linux。

谢谢!

最佳答案

使用 find 和 GNU sed:

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

关于linux - 在 Bash Shell 中编写文件编辑脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22690150/

相关文章:

linux - 这个 bash 文件名提取技术的用途?

linux - 如何构建可靠的工具链

linux - 让 imagemagick 在共享主机上工作

bash - 变量中的 rsync 选项

c++ - NSTask 的碳当量?

shell - 如何删除打开 Linux shell 时出现的静态消息?

linux - 使用 ImageMagick : too many exceptions and blinking problem 创建 GIF 图像时出错

MySQL 查询在 linux shell 脚本中中断,但查询在 mysql 命令行中运行

Bash 动态命令行输出

bash - 使用 "mutt"将 Html 页面作为电子邮件发送