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 sgfstrip.

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

sgfstrip

% sgfstrip [-h] [-m] [-t] [-pw] [-pe] [-pass] tags < input > output

The utility sgfstrip reads an SGF file, strips it and writes it to stdout. Leading and trailing whitespace for all property values is removed. Properties with one of the given names (in all caps) are removed. Empty nodes are removed.

Options:

-h
Don't touch the head (the first node, the root node) of each game.
-m
Don't touch the middle (all except head and tail) of each game.
-t
Don't touch the tail of each game.
-pe
Preserve empty nodes.
-pw
Preserve whitespace (in text fields).
-pass
Strip trailing passes.

Examples

% sgfstrip BL WL < in.sgf > out.sgf
Strip away all occurrences of BL[] and WL[] node properties.

% sgfstrip -t BL WL < in.sgf > out.sgf
Strip away all occurrences of BL[] and WL[] node properties, except for those in the final node.

% sgfstrip -h -t C < in.sgf > out.sgf
Strip away all comments, but leave those at start and end.
Often a final comment contains meta-information that should not be lost.
The tail, the final node, is the final node of the main variation, not textually the last node. E.g.
% cat in.sgf
(;EV[ The game ](;B[aa]C[the actual game])(;B[tt]C[a variation]))

% sgfstrip -t C < in.sgf
(;
EV[The game]

(;B[aa]
C[the actual game]
)
(;B[tt])
)

It is possible to strip only those occurrences of a given tag whose value contains a given string.

% sgfstrip C:abc < in.sgf > out.sgf
This removes all comments that contain "abc". And
% sgfstrip C=abc < in.sgf > out.sgf
will remove only the comments that are precisely "abc".

Comments

See also sgfmerge. It will strip the variations off a game, and only leave the main line.
% sgfmerge < in.sgf
(;
EV[ The game ]

;B[aa]
C[the actual game]
)

A general SGF utility cannot blindly strip empty properties. The properties B[] and W[] are used to indicate a pass. The standard also indicates that VW[] can be used to reset a restriction introduced by an earlier VW[here:there]. However, sgf will delete most empty properties. Comments and variations are stripped by sgf -c.