【问题标题】:search same file in subdirectories and replace string in all of them在子目录中搜索相同的文件并替换所有子目录中的字符串
【发布时间】:2017-03-03 00:13:48
【问题描述】:

你好,我是 shell 脚本的菜鸟, 我想创建一个 findandfix.sh 以在 FOLDER1 内的所有目录中搜索名为 file.xml 的所有文件,并将所有以 <linex= 开头的特定行替换为 <activate=option1,option2

  FOLDER1
      |
      |---->FOLDER2
      |           |->file.xml
      |
      |---->FOLDER3
      |           |->file.xml
      |
      |---->FOLDER4
      |           |->file.xml
      |
      |---->FOLDER5
                  |->file.xml

我认为这需要使用findsed,但我不知道如何将它们组合在一起来完成这项工作。

【问题讨论】:

    标签: linux shell replace sed find


    【解决方案1】:

    如果我理解你的话:

    find /system/home/user/folder1 -name 'file.xml' -exec sed -i 's@linex=@activate=option1,option2@' {} \;
    

    测试前做个备份,或者去掉-i开关

    【讨论】:

    • 喜欢“/system/home/user/folder1”
    • 谢谢,@ 代表
    • @ 是一个分隔符
    • 你为什么哭泣?
    猜你喜欢
    • 2012-05-22
    • 2018-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多