GoGrinder / update-disorted.sh

Sub-page of GoGrinder

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.

# 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`"
upperNum=20000 # maxNum in newColl
for (( Num = lowerNum ; Num <= upperNum ; Num ++ ))
    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 ))}
      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
      (( count++ ))
printf "\n $count files, Finished: `date`"

GoGrinder / update-disorted.sh last edited by on November 27, 2014 - 20:31
RecentChanges · StartingPoints · About
Edit page ·Search · Related · Page info · Latest diff
[Welcome to Sensei's Library!]
Search position
Page history
Latest page diff
Partner sites:
Go Teaching Ladder
Login / Prefs
Sensei's Library