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 [-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, ...


-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.)
Start counting from 0.
-x ARG
Use "ARG" as prefix. (Default is "X-".)
Use "ARG" as format. (Default is "X-%04d.sgf".)
The format must contain precisely one integer conversion.
Clean away all text before and/or after the games. Output files are pure SGF.
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.


% sgfsplit -d0 < kisei.sgf
% ls -1v

% sgfsplit -x Hon- honinbo.sgf
% ls -1

% 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

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.