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)

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 xela on March 13, 2024 - 00:18
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