【问题标题】:Filter files in all subdirectories and save them with the same name?过滤所有子目录中的文件并以相同的名称保存?
【发布时间】:2021-08-15 04:28:38
【问题描述】:

如何删除目录中每个文件中的重复行,并使用单行命令将固定数据保存在同一个文件中?

以下不起作用:

   find . -type f -execdir cat {} | sort | uniq > {} \; 

   find . -type f | xargs -I{} cat {} | sort | uniq > {}

   find . -type f | xargs -I{} cat {} | sort | uniq > {}.new && mv {}.new {}

“>”符号打破了链条..

【问题讨论】:

    标签: linux shell filter command text-files


    【解决方案1】:

    在 exec 中放置一个 shell 包装器:

    find . -type f -exec sh -c 'sort "$1" | uniq > "$1.new" && mv "$1.new" "$1"' _ {} \;
    

    【讨论】:

      猜你喜欢
      • 2023-01-04
      • 1970-01-01
      • 2020-10-20
      • 1970-01-01
      • 1970-01-01
      • 2017-07-03
      • 1970-01-01
      • 2019-03-04
      • 2020-12-23
      相关资源
      最近更新 更多