-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:cgutteridge/Grinder
- Loading branch information
Showing
13 changed files
with
810 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Grinder: | ||
Grinder: | ||
|
||
etc/ bin/grinder.pl and lib/ are LGPL. | ||
perl-lib/ is the liceses of the packages we've added. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Text::CSV; | ||
|
||
my $csv = Text::CSV->new(); | ||
binmode(STDIN, ":utf8" ); | ||
binmode(STDOUT, ":utf8" ); | ||
|
||
my $skip_rows = 1; | ||
my $map_file = $ARGV[0]; | ||
my $field_number = $ARGV[1]-1; | ||
|
||
my $map = {}; | ||
open( MAP, "<:utf8", $map_file ) or die "can't read $map_file: $!"; | ||
while( my $line = readline( MAP ) ) | ||
{ | ||
if( !$csv->parse($line) ) | ||
{ | ||
my $err = $csv->error_input; | ||
die( "Failed to parse line: $err", 1 ); | ||
} | ||
my @row = $csv->fields(); | ||
$map->{$row[1]} = $row[0]; | ||
} | ||
close MAP; | ||
|
||
|
||
my $line_n = 0; | ||
while( my $line = readline( STDIN ) ) | ||
{ | ||
$line_n++; | ||
if( !$csv->parse($line) ) | ||
{ | ||
my $err = $csv->error_input; | ||
die( "Failed to parse line: $err", 1 ); | ||
} | ||
if( $skip_rows ) { $skip_rows--; next; } | ||
my @row = $csv->fields(); | ||
if( defined $row[$field_number] && $row[$field_number] ne '' ) | ||
{ | ||
my $mapped = $map->{$row[$field_number]}; | ||
if( !defined $mapped) | ||
{ | ||
die "Unmapped value on line $line_n: \"".$row[$field_number]."\""; | ||
} | ||
$row[$field_number] = $mapped; | ||
} | ||
|
||
$csv->print (*STDOUT, \@row ); | ||
print "\n"; | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.