--- /dev/null
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+use IO::File;
+
+for my $sgf (@ARGV) {
+ my %sgf;
+ my $fh = new IO::File $sgf, 'r'
+ or warn "Unable to open $sgf for reading: $!"
+ and next;
+ while (<$fh>) {
+ chomp;
+ my ($field,$value) = $_ =~ /^([A-Z]{2})\[([^\]]+)\]/;
+ next unless defined $field;
+ if ($field =~ /^[WB]R$/) {
+ $value =~ s/\s+dan/d/;
+ $value =~ s/\s+pro/p/;
+ $value =~ s/\s+kyu/k/;
+ }
+ $sgf{$field} = $value;
+ }
+ undef $fh;
+ my $new_file = join('_',
+ map {s/\s+/_/g;
+ s/,//g;
+ s/[_-]+/_/g;
+ s/^_//;
+ s/_$//;
+ lc($_);
+ }
+ map{defined $_?($_):()}
+ (@sgf{qw(EV RO PB BR)},'v',
+ @sgf{qw(PW WR DT RE)}
+ )
+ ).'.sgf';
+ next if $sgf eq $new_file;
+ warn "$new_file already exists" and next if -e $new_file;
+ rename($sgf,$new_file);
+}