freesky

Untitled

Oct 27th, 2015
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.71 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4.  
  5. # check command-line arguments
  6. if (($#ARGV + 1) != 2) {
  7.     die "Usage: $0 INPUT-FILE OUTPUT-FILE\n";
  8. }
  9.  
  10. # read the entire file
  11. open(FILE, "$ARGV[0]") or die "Can't open $ARGV[0] for reading!\n";
  12. my @lines = <FILE>;
  13. close(FILE);
  14.  
  15. # skip header
  16. shift @lines;
  17. shift @lines;
  18.  
  19. # join together
  20. my $lines = join('', @lines);
  21.  
  22. # remove empty lines, fix tabulation and decimal sign
  23. (my $converted = $lines) =~ s/^(\d+?),(\d+?)(\s+?)\n//gm;
  24. $converted =~ s/,/./gm;
  25. $converted =~ s/^(\d+?)\.(\d+?)(\s+?)(\d+?)\.(\d+?)\n/\1.\2\t\4.\5\n/gm;
  26.  
  27. # write result
  28. open(FILE, '>', $ARGV[1]) or die "Can't open $ARGV[1] for writing!\n";
  29. print FILE $converted;
  30. close(FILE);
  31.  
  32. exit(0);
Advertisement
Add Comment
Please, Sign In to add comment