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. Javascript差異百分比數學
- 4. 計算列百分比差異
- 5. 搞清楚百分比差異
- 6. 將差異轉換爲百分比
- 7. 日誌文件的差異百分比
- 8. 百分比差值從計算
- 9. 的Tableau - 百分比差值計算
- 10. Spark:列值的百分比百分比
- 11. 標籤散點圖上兩點之間的差異百分比差異
- 12. 分配百分比與R
- 13. 按價值或價值百分比計算百分比
- 14. 計算表上各行之間的百分比差異
- 15. 如何計算SQL中的百分比差異?
- 16. 計算兩個HTML文件的百分比差異
- 17. 如何衡量代碼庫中的百分比差異?
- 18. 計算方程之間的百分比差異
- 19. 百分比寬度上的一個像素差異
- 20. 檢測HTML頁面之間的差異百分比
- 21. PlasticSCM:查看二進制文件的差異百分比
- 22. 2圖像之間的百分比差異
- 23. 報表服務中的圖表百分比差異
- 24. 瀏覽器之間的左/右百分比差異
- 25. 兩個文本文件之間的百分比差異
- 26. Sql Server Reporting Services:如何計算百分比差異?
- 27. 舍入總誤差百分比
- 28. 基於百分比佈局的差距
- 29. 2組3D點的百分比誤差
- 30. ř計算與百分比
您可以使用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