Skip to content

Instantly share code, notes, and snippets.

@usaturn
Created March 22, 2013 15:19
Show Gist options
  • Select an option

  • Save usaturn/5222086 to your computer and use it in GitHub Desktop.

Select an option

Save usaturn/5222086 to your computer and use it in GitHub Desktop.
画像重複検出のリファクタリング? awkは1回でいいのさ
# 260ファイル 計54MBに対して処理
# timeコマンドで計測。
# /dev/nullに捨てる事によりオーバーヘッドを最小限にした。
# 初めにmd5sumを1回、パイプをいくつか挟み、シェルのfor文の中でさらにmd5sumを使用
time for i in $(md5sum *.jpg|awk '{print $1}'|sort|uniq -c|awk '{print $1,$2}'|grep -v ^1|awk '{print $NF}');do md5sum *.jpg|grep $i;done > /dev/null
# 結果 20秒以上
# real 0m23.894s
# user 0m12.430s
# sys 0m11.072s
# md5sumの結果をawk一発で処理
time md5sum *.jpg|awk '{num[$1]++; hash[$1]=hash[$1]"\t"$2}END{for(i in num) if(num[i] > 1) print i,hash[i]}' > /dev/null
# 結果 1秒未満
# real 0m0.271s
# user 0m0.139s
# sys 0m0.154s
# これで君も、重複画像ファイルとはおさらばさ!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment