This script (for within Linux and Cygwin [Windows]) can sort .sgf and GoGrinder's .dat files (from within Grinder's stats/ directory) simultaneously. It handles also the problematic files where unicode characters on the same line as the DI[...]-identifier disturb sed. When you work with Cygwin: the script in the file must not contain LF-CR combinations (0D0A) for line endings. Use a real editor to save the file (e.g. notepad2 ,notepad++ etc.).
You begin in a folder with all new .sgf and the .dat files from the stats directory. Start the script inside this folder! The result of the script will be the 30k...6d folders with the sgf files in the directory, where you started and (also there) a stats/ folder with the corresponding sub-directories with the .dat files.
#!/bin/bash # update-disorted.sh by RueLue Apr.2013 # (based on Oliver Richman's disort.sh from 2006.) # Works in bash (Linux, and in Cygwin [Windows] too!). # Please test it in Mac and report! # # Sorts .sgf files and corresponding .dat files from GoGrinder's stats # directory into directories based on the contents of the DI tag. # ex. If the file contains DI[4k] then it is moved into ./4k and and the # corresponding .dat (if it exists) to stats/4k. # The script also handles the problem with unicode characters, where # sed stumbles (I couldn't yet find a way to let sed do it complete). # # Before running the script you make a backup (zip or similar) of your # two goproblems.com-folders: one in problems/ and one in stats/ # now you move (or copy) all files from the subdirectories of # stats/goproblems.com to one folder where also the new sgf are. # Start this script inside that folder. When all goes fine, you may delete # the old sgf.
echo " Beginning: `date`" lowerNum=0 count=1 upperNum=20000 # maxNum in newColl for (( Num = lowerNum ; Num <= upperNum ; Num ++ )) do if [ -f $Num.sgf ]; then printf " Processing file $count: $Num.sgf\r" dirname=`sed -n 's/^.*DI\[//;T ready;s/].*$//p;: ready' $Num.sgf` if [ "`expr length $dirname`" -gt "3" ] then dirname=${dirname:0:$(( `expr index "$dirname" ]` - 1 ))} fi mkdir $dirname 2>/dev/null mv $Num.sgf $dirname if [ -f $Num.dat ]; then mkdir stats/$dirname 2>/dev/null mv $Num.dat stats/$dirname fi (( count++ )) fi done printf "\n $count files, Finished: `date`"