Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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: $?";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement