Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@fastzombies
Created October 20, 2016 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fastzombies/d510c1321b56da40395506a0f1179931 to your computer and use it in GitHub Desktop.
Save fastzombies/d510c1321b56da40395506a0f1179931 to your computer and use it in GitHub Desktop.
Convert Wells Fargo csv to my own csv for import into Excel
#!/usr/bin/perl -w
use strict;
my $self=$0;
# (1) quit unless we have the correct number of command-line args
my $num_args = $#ARGV + 1;
if ($num_args != 2) {
print "\nUsage: $self <raw WF csv> <output>\n";
exit;
}
# (2) we got two command line args, so assume they are the
# WF input csv and output csv
my $infile=$ARGV[0];
my $outfile=$ARGV[1];
# (3) print command used
print "${self}: $infile $outfile\n";
# (4) open files
open (INFILE, $infile);
open (OUTFILE, ">$outfile") or die $!;
# (5) read infile
my @contents = <INFILE>;
@contents = reverse (@contents);
# (6) parse infile and write to outfile
foreach (@contents) {
chomp;
s/\"//g;
my $len=length();
if ($len > 0 ) {
my ($date, $amount, $star, $blank, $desc) = split (/,/, $_);
if ($amount < 0) {
$amount = abs($amount);
print OUTFILE "$date,$desc,,$amount \n";
} else {
print OUTFILE "$date,$desc,$amount, \n";
}
}
}
# (7) close files
close (INFILE);
close (OUTFILE);
# (8) delete infile
my @args = ("rm", "-f", $infile);
system(@args) == 0 or die "system @args failed: $?";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment