distsort.sh not working well for some SGF files.

Post Reply
Lenbok
Posts: 1
Joined: Tue May 03, 2011 2:13 am

distsort.sh not working well for some SGF files.

Post by Lenbok »

I downloaded the raw SGF to make graded collections for us offline on my android phone. The distsort.sh script linked on the download page had problems with many files being assigned a difficulty label composed of a bunch funny characters plus extra tags. I didn't look into it in a great deal, but used the following version of the script to happily sort them:

# Based on disort.sh by Oliver Richman
# 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
for fname in $(ls -1 *.sgf); do
difficulty=$(<$fname dos2unix | tr -cd '\11\12\40-\176' | sed -n '/DI\[[0-9]\+[dk]\]/s/.*DI\[\([0-9]\+[dk]\)\].*/\1/p')
if [ ! "$difficulty" ]; then
difficulty=unknown
fi
echo Processing $fname with difficulty $difficulty
mkdir -p "$difficulty"
mv $fname $difficulty
done
Post Reply