removeTag

   

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)

Usage

Install perl and the Slurp module, copy the program below into a text file and call it removeTag.pl.

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;

removeTag last edited by deg on January 29, 2007 - 18:05
RecentChanges · StartingPoints · About
Edit page ·Search · Related · Page info · Latest diff
[Welcome to Sensei's Library!]
RecentChanges
StartingPoints
About
RandomPage
Search position
Page history
Latest page diff
Partner sites:
Go Teaching Ladder
Goproblems.com
Login / Prefs
Tools
Sensei's Library