removeTag
Keywords: Software
This Perl program allows you to strip unwanted properties from an SGF file, plus any empty Comment tags.
(Thanks to Chris Goldsmith for the command line argument handling)
[edit]
Usage
Install Perl and the Slurp module, copy the program below into a text file and call it removeTag.pl.
[edit]
The Program
#!/usr/bin/perl # # removeTag.pl by D. Gilder # # Usage removeTag.pl infile outfile (-t Tag) # # Example: # removeTag.pl infile.sgf outfile.sgf -t CR -t N # will remove the sgf flags "CR" and "N" from infile.sgf # and write the resulting file to outfile.sgf # # Empty Comment tags are also removed. # use File::Slurp ; $FromFile = shift; $ToFile = shift; my $contents = read_file( $FromFile ) ; open ( TOFILE, ">$ToFile" ) or die "Unable to open file $ToFile"; @TagsToRemove = ();
while ( $ARGV = shift ) { if ( $ARGV eq "-t" ) { $TagsToRemove[$#TagsToRemove+1] = shift or die "-t specified without sgf tag"; } } foreach $Tag (@TagsToRemove) { $contents =~ s/$Tag(\[.*?\])+//g; } $contents =~ s/C\[\n*\]//g; print TOFILE $contents; close TOFILE;