# disort.sh by Oliver Richman on August 29th 2006, slightly modified by Ulrich Goertz.
# Works in bash (and cygwin for windows too!)
# Sorts .SGF files into directories based on the contents of the DI tag.
# ex. If the file contains DI[4k] then it is moved into ./4k
# Note that this only works properly, if there is only one occurence of the DI[...] 
# tag in the sgf file.
# Please do not redistribute modified versions of this file.
#
for fname in *.sgf
do
	echo Processing $fname
	export DIFF=`tr -d ' \t\r\n' < $fname | sed -e 's/\(^.*DI\[\)\([^]]*\)\(\].*$\)/\2/'`
	if (test ! -e $DIFF ) then mkdir $DIFF; fi
	if (test -d $DIFF ) then mv $fname $DIFF; fi
done
