sgfutils

The package sgfutils contains a few command line utilities that help working with SGF files that describe go (igo, weiqi, baduk) games. This page is about sgfsplit.

See also sgf, sgfcharset, sgfcheck, sgfcmp, sgfdb, sgfdbinfo, sgfinfo, sgfmerge, sgfstrip, sgftf, sgftopng, sgfvarsplit, sgfx, ugi2sgf.

sgfsplit

% sgfsplit [-d#] [-s#] [-z] [-x prefix] [-F format] [-c] [-p] [files]

The utility sgfsplit reads one or more SGF files that contain collections of game records and splits them into files each containing a single game. Introductory text before each game is preserved. The output files get names produced from a format, by default "X-%04d.sgf" and a counter that counts from 1: X-0001.sgf, X-0002.sgf, ...

Options:

-d ARG
Use an output counter that is zero padded to ARG digits.
(Default is 4. Use -d0 to get numbers without zero padding.)
-s ARG
Start counting from ARG. (Default is 1.)
-z
Start counting from 0.
-x ARG
Use "ARG" as prefix. (Default is "X-".)
-F ARG
Use "ARG" as format. (Default is "X-%04d.sgf".)
The format must contain precisely one integer conversion.
-c
Clean away all text before and/or after the games. Output files are pure SGF.
-p
Preserve the text following the last game. By default trailing junk is discarded. With this option, if there is trailing junk, it is stored in the last file, a file without game.

Examples

% sgfsplit -d0 < kisei.sgf
% ls -1v
X-1.sgf
X-2.sgf
...
X-119.sgf

% sgfsplit -x Hon- honinbo.sgf
% ls -1
Hon-0001.sgf
Hon-0002.sgf
...
Hon-0259.sgf

% export LC_ALL=fa_IR.utf8
% sgfsplit -F "Judan-%I02u" judan.sgf
% ls
Judan-۱   Judan-۱۳  Judan-۱۷  Judan-۲۰  Judan-۲۴  Judan-۲۸  Judan-۴  Judan-۸
Judan-۱۰  Judan-۱۴  Judan-۱۸  Judan-۲۱  Judan-۲۵  Judan-۲۹  Judan-۵  Judan-۹
Judan-۱۱  Judan-۱۵  Judan-۱۹  Judan-۲۲  Judan-۲۶  Judan-۳   Judan-۶  judan.sgf
Judan-۱۲  Judan-۱۶  Judan-۲   Judan-۲۳  Judan-۲۷  Judan-۳۰  Judan-۷

The inverse operation, that of combining games into a collection, is trivial:

% cat game*.sgf > collection.sgf

The number of games in a collection is reported by sgfinfo:

% sgfinfo -N guanzi_pu.sgf
1477

The utility sgf can also split collections. It removes leading and trailing junk, and also otherwise polishes the result. The present utility tries to change as little as possible, and only adds a final newline where needed.

See also sgfvarsplit, that splits a game into its variations.