#!/bin/bash

EXCEPTIONS=`ack-grep --type php 'throw new' -A5 | grep '[[:digit:]]\{10\}'`

DUPLICATES=`echo $EXCEPTIONS |
awk '{
	for(i=1; i<=NF; i++) {
		tmp=match($i, /[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/);
		if(tmp) {
			print $i
		}
	}
}' | cut -d';' -f1 | tr -cd '0-9\012' | sort | uniq -d`

for CODE in $DUPLICATES; do
	echo "Possible duplicate exception code $CODE"
	ack-grep --type php $CODE
	echo
	echo
done
