Here there is a Perl solution and also a SED one:
#!/usr/bin/perl
use strict;
use warnings;
while (<>) {
chomp;
if (/^[^0-9]/) {
print "$_\n";
next;
}
my @Fields = split /,/, $_, 2;
my ($Month, $Day, $Year) = split /\//, $Fields[0];
print "$Year-$Month-$Day, $Fields[1]\n";
}
__END__
sed -i.bak 's/^\([0-9]\+\)\/\([0-9]\+\)\/\([0-9]\+\)/\3-\1-\2/' *.csv
Yesterday on my way home I realized that the Perl script was horrible, a one-liner should be OK, like the one below:
perl -i.bak -pe 's!(\d+)/(\d+)/(\d+)!\3-\1-\2!' *.csv
No comments:
Post a Comment