-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathspc2tab.pl
executable file
·49 lines (44 loc) · 1.01 KB
/
spc2tab.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl
# Script: spc2tab.pl
# Description: Replaces multispace-delim files to tsv files
# Author: Steven Ahrendt
# email: [email protected]
# Date: 05.08.2014
##################################
use warnings;
use strict;
use Getopt::Long;
use lib '/rhome/sahrendt/Scripts';
#####-----Global Variables-----#####
my $input;
my ($help,$verb);
GetOptions ('i|input=s' => \$input,
'h|help' => \$help,
'v|verbose' => \$verb);
my $usage = "Usage: spc2tab.pl -i input\n";
die $usage if $help;
die "No input.\n$usage" if (!$input);
#####-----Main-----#####
my $filename = (split(/\./,$input))[0];
open(my $in,"<",$input) or die "Can't open $input: $!\n";
open(my $out,">","$filename.tsv");
while(my $line = <$in>)
{
$line =~ s/^\s+//;
$line =~ s/\s+$//;
if($line =~ /^#/)
{
print $out $line,"\n";
}
else
{
chomp $line;
my @data = split(/\s{2,}/,$line);
print $out join("\t",@data),"\n";
}
}
close($in);
close($out);
warn "Done.\n";
exit(0);
#####-----Subroutines-----#####