Created
October 20, 2016 20:41
-
-
Save fastzombies/d510c1321b56da40395506a0f1179931 to your computer and use it in GitHub Desktop.
Convert Wells Fargo csv to my own csv for import into Excel
This file contains hidden or 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
#!/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