Page 1 of 1 not working well for some SGF files.

PostPosted: Tue May 03, 2011 5:21 pm
by Lenbok
I downloaded the raw SGF to make graded collections for us offline on my android phone. The 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 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
echo Processing $fname with difficulty $difficulty
mkdir -p "$difficulty"
mv $fname $difficulty