apolzek

rmhash.sh

Apr 6th, 2020
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.89 KB | None | 0 0
  1. #by: apolzek
  2.  
  3. md5sum * | sort -n > .file
  4. filename='.file'
  5. n=1
  6. x=1
  7. while read line; do
  8.     current_hash=$(echo $line | awk {'print $1'})
  9.     echo "[debugging] current_hash: $current_hash"
  10.     x=$(($n + 1))
  11.     next_hash=$(awk NR==$(echo $x) .file | awk {'print $1'})
  12.     echo "[debugging] next_hash:  $next_hash"
  13.  
  14.     if [ -z $next_hash ]; then
  15.         echo "[debugging] end"
  16.         rm .file
  17.         exit
  18.     fi
  19.  
  20.     if [ $current_hash == $next_hash ]; then
  21.         echo "[debugging] remove duplicate"
  22.  
  23.         first_duplicate_file=$(echo $line | cut -c34-)
  24.         echo "[debugging] name first duplicate file: $first_duplicate_file"
  25.  
  26.         second_duplicate_file=$(awk NR==$(echo $x) .file | cut -c35-)
  27.         echo "[debugging] name second duplicate file: $second_duplicate_file"
  28.    
  29.         rm "$second_duplicate_file"
  30.     fi
  31.     echo ""
  32.     n=$((n+1))
  33. done < $filename
Add Comment
Please, Sign In to add comment