请不要告诉我.我想写剧本。
我有很多文件副本,有200多份。
我做了(正在建造中)一个bash脚本
对每个文件都使用md5sum,然后使用uniq我将重复的md5s放在
另一个文件,然后我再次检查副本并将整行
在第三个最终文件中。
现在问题是.我可以一个接一个地去除这些陷阱。
但我的问题是:是否有可能只找到陷阱并把第四个文件安全删除?
这是剧本
#!/bin/bash
# Script is "under construction"
# First we make the md5sum
find mp3 -type f -print0 |xargs -0 md5sum|tee firstfile.txt
# Then we find all the md5sum identical and put in secondfile.txt
sort +1rn -2 +0 -1 firstfile.txt |awk '{print $1}'|uniq -d > secondfile.txt
# then we extract from the secondfile and firstfile md5sum and name
while read line;do grep -i $line firstfile.txt;done < secondfile.txt > thirdfinal.txt现在,problem..thirdfinal.txt包含了许多类似于
625e8fd5f878b19b39826db539e01cda mp3/16.mp3
625e8fd5f878b19b39826db539e01cda mp3/12.mp3
625e8fd5f878b19b39826db539e01cda mp3/20.mp3
625e8fd5f878b19b39826db539e01cda mp3/21.mp3
625e8fd5f878b19b39826db539e01cda mp3/19.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/9.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/5.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/7.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/10.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/8.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/3.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/2.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/1.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/11.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/6.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/4.mp3
d7fbd596e86dfdb546092f34ab8ca576 mp3/25.mp3
d7fbd596e86dfdb546092f34ab8ca576 mp3/25.mp3我的问题is...how到grep获得的第三个文件
第四个文件,包括所有的duplicates..except (第一个)
行(否则删除所有文件,包括原始文件!)
所以你可以有一排重复的,但同时
保留原来的那个。
第四个文件必须如下所示
625e8fd5f878b19b39826db539e01cda mp3/12.mp3
625e8fd5f878b19b39826db539e01cda mp3/20.mp3
625e8fd5f878b19b39826db539e01cda mp3/21.mp3
625e8fd5f878b19b39826db539e01cda mp3/19.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/5.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/7.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/10.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/8.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/3.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/2.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/1.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/11.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/6.mp3
7eac02c26935323fe167d6e39ef6bd0a mp3/4.mp3
d7fbd596e86dfdb546092f34ab8ca576 mp3/25.mp3建议?请不要回答:使用fdup或外部程序
喜欢bash自动化
发布于 2018-01-15 01:13:18
awk '{ if (seen[$1]++) print }' < file3 > file4这将在第1列中构建md5sums的awk数组;如果某个特定md5sum的数组值已经被看到(例如,不是第一次看到它),那么它将打印这条线。无论哪种方法,它都会从默认的零开始增加该md5sum的数组值。
另一种方法是使用bash关联数组:
unset md5sums
declare -A md5sums
while read md5sum path
do
((md5sums[$md5sum]++))
[[ ${md5sums[$md5sum]} -gt 1 ]] && printf "%s %s\n" "$md5sum" "$path"
done < file3 > file4https://unix.stackexchange.com/questions/417139
复制相似问题