7
A
回答
6
2
这里有一个脚本,将比较所有.txt文件,并显示有超过15%的重复的那些:
#!/bin/bash
# walk through all files in the current dir (and subdirs)
# and compare them with other files, showing percentage
# of duplication.
# which type files to compare?
# (wouldn't make sense to compare binary formats)
ext="txt"
# support filenames with spaces:
IFS=$(echo -en "\n\b")
working_dir="$PWD"
working_dir_name=$(echo $working_dir | sed 's|.*/||')
all_files="$working_dir/../$working_dir_name-filelist.txt"
remaining_files="$working_dir/../$working_dir_name-remaining.txt"
# get information about files:
find -type f -print0 | xargs -0 stat -c "%s %n" | grep -v "/\." | \
grep "\.$ext" | sort -nr > $all_files
cp $all_files $remaining_files
while read string; do
fileA=$(echo $string | sed 's/.[^.]*\./\./')
tail -n +2 "$remaining_files" > $remaining_files.temp
mv $remaining_files.temp $remaining_files
# remove empty lines since they produce false positives
sed '/^$/d' $fileA > tempA
echo Comparing $fileA with other files...
while read string; do
fileB=$(echo $string | sed 's/.[^.]*\./\./')
sed '/^$/d' $fileB > tempB
A_len=$(cat tempA | wc -l)
B_len=$(cat tempB | wc -l)
differences=$(sdiff -B -s tempA tempB | wc -l)
common=$(expr $A_len - $differences)
percentage=$(echo "100 * $common/$B_len" | bc)
if [[ $percentage -gt 15 ]]; then
echo " $percentage% duplication in" \
"$(echo $fileB | sed 's|\./||')"
fi
done < "$remaining_files"
echo " "
done < "$all_files"
rm tempA
rm tempB
rm $all_files
rm $remaining_files
5
https://superuser.com/questions/347560/is-there-a-tool-to-measure-file-difference-percentage有这很好地解决,
wdiff -s文件1。 txt file2.txt
更多选项请参阅man wdiff。
相关问题
- 1. 计算与平均值的差异百分比
- 2. 计算差异和百分比
- 3. 将差异转换为百分比
- 4. 计算百分比差异python
- 5. 日志文件的差异百分比
- 6. 计算列百分比差异
- 7. Javascript差异百分比数学
- 8. 搞清楚百分比差异
- 9. 百分比差值从计算
- 10. 的Tableau - 百分比差值计算
- 11. mysql与上一行的百分比差异
- 12. 如何计算列的不同值的差异百分比
- 13. Java:查找百分比差
- 14. Spark:列值的百分比百分比
- 15. 标签散点图上两点之间的差异百分比差异
- 16. Highcharts百分比值
- 17. SSRS中最小值和最大值的表达百分比差异
- 18. 分配百分比与R
- 19. 按价值或价值百分比计算百分比
- 20. css与百分比+静态值
- 21. Javascript。计算一个百分比会导致1%的差异
- 22. 计算表上各行之间的百分比差异
- 23. 两幅图像之间的百分比差异
- 24. PlasticSCM:查看二进制文件的差异百分比
- 25. 计算基于年份和类别的百分比差异
- 26. 计算R数据帧的差异百分比
- 27. Cognos Report Studio 10.2交叉表报告总差异百分比
- 28. 如何计算SQL中的百分比差异?
- 29. 如何衡量代码库中的百分比差异?
- 30. 2图像之间的百分比差异
您可以使用sdiff并计算分隔符,然后除以行数。 – MJB 2010-04-27 16:20:26
diff fileA fileB | wc -l 除以wc -l fileA //似乎是一个有趣的手动方式来完成它。 – cdated 2010-04-27 16:28:36
但问题是,如果有差异,你会得到3行 - orig,new和description。所以你可能会高估。来自wc的man文件的 – MJB 2010-04-27 17:27:01