Skip to content

Instantly share code, notes, and snippets.

@gravesm
Created March 25, 2015 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gravesm/6bfbc3b895e34adcea44 to your computer and use it in GitHub Desktop.
Save gravesm/6bfbc3b895e34adcea44 to your computer and use it in GitHub Desktop.
dedup
#!/usr/bin/env bash
####
# ./dedup FROM TO
#
# move duplicate emails from FROM to TO
####
duplicates=$(grep --no-filename -rE "^To:\s[[:alpha:]]+" $1 | sort | uniq -c | \
grep -E "[[:blank:]]([2-9]|[[:digit:]]{2,})" | cut -d : -f 2)
for i in $duplicates
do
n=0
for f in $(grep -rl "To: $i" $1)
do
if [ $n -gt 0 ]
then
mv "$f" "$2"
fi
n+=1
done
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment