Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- # check command-line arguments
- if (($#ARGV + 1) != 2) {
- die "Usage: $0 INPUT-FILE OUTPUT-FILE\n";
- }
- # read the entire file
- open(FILE, "$ARGV[0]") or die "Can't open $ARGV[0] for reading!\n";
- my @lines = <FILE>;
- close(FILE);
- # skip header
- shift @lines;
- shift @lines;
- # join together
- my $lines = join('', @lines);
- # remove empty lines, fix tabulation and decimal sign
- (my $converted = $lines) =~ s/^(\d+?),(\d+?)(\s+?)\n//gm;
- $converted =~ s/,/./gm;
- $converted =~ s/^(\d+?)\.(\d+?)(\s+?)(\d+?)\.(\d+?)\n/\1.\2\t\4.\5\n/gm;
- # write result
- open(FILE, '>', $ARGV[1]) or die "Can't open $ARGV[1] for writing!\n";
- print FILE $converted;
- close(FILE);
- exit(0);
Advertisement
Add Comment
Please, Sign In to add comment