Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4. my $self=$0;
  5.  
  6. # (1) quit unless we have the correct number of command-line args
  7. my $num_args = $#ARGV + 1;
  8. if ($num_args != 2) {
  9. print "\nUsage: $self <raw WF csv> <output>\n";
  10. exit;
  11. }
  12.  
  13. # (2) we got two command line args, so assume they are the
  14. # WF input csv and output csv
  15. my $infile=$ARGV[0];
  16. my $outfile=$ARGV[1];
  17.  
  18. # (3) print command used
  19. print "${self}: $infile $outfile\n";
  20.  
  21. # (4) open files
  22. open (INFILE, $infile);
  23. open (OUTFILE, ">$outfile") or die $!;
  24.  
  25. # (5) read infile
  26. my @contents = <INFILE>;
  27. @contents = reverse (@contents);
  28.  
  29. # (6) parse infile and write to outfile
  30. foreach (@contents) {
  31. chomp;
  32. s/\"//g;
  33. my $len=length();
  34. if ($len > 0 ) {
  35. my ($date, $amount, $star, $blank, $desc) = split (/,/, $_);
  36. if ($amount < 0) {
  37. $amount = abs($amount);
  38. print OUTFILE "$date,$desc,,$amount \n";
  39. } else {
  40. print OUTFILE "$date,$desc,$amount, \n";
  41. }
  42. }
  43. }
  44.  
  45. # (7) close files
  46. close (INFILE);
  47. close (OUTFILE);
  48.  
  49. # (8) delete infile
  50. my @args = ("rm", "-f", $infile);
  51. system(@args) == 0 or die "system @args failed: $?";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement