[英]Filter files in all subdirectories and save them with the same name?
How to remove duplicate lines in every file in directory and save the fixed data in the same file with a single line command?如何使用单行命令删除目录中每个文件中的重复行并将固定数据保存在同一文件中?
the following do not work:以下不起作用:
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 {}
the '>' symbol breaks the chain.. '>' 符号打破了链条..
Put a shell wrapper in the exec:将 shell 包装器放入 exec 中:
find . -type f -exec sh -c 'sort "$1" | uniq > "$1.new" && mv "$1.new" "$1"' _ {} \;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.