forked from jmeneghin/perl-for-reysenbach-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_carriage_returns.pl
More file actions
56 lines (56 loc) · 1.88 KB
/
remove_carriage_returns.pl
File metadata and controls
56 lines (56 loc) · 1.88 KB
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
50
51
52
53
54
55
56
#!/usr/bin/perl -w
###########################
### Jennifer Meneghin ###
### May 18, 2011 ###
###########################
#---------------------------------------------------------------------------------------------------------------------------
#Deal with passed parameters
#---------------------------------------------------------------------------------------------------------------------------
if ($#ARGV == -1) {
&usage;
}
$in_file = "";
$out_file = "clean.txt";
%my_args = @ARGV;
for $i (sort keys %my_args) {
if ($i eq "-i") {
$in_file = $my_args{$i};
}
elsif ($i eq "-o") {
$out_file = $my_args{$i};
}
else {
print "\nUnrecognized argument: $i\n\n";
&usage;
}
}
unless ( open(IN, "$in_file") ) {
print "\nGot a bad input file: $in_file\n\n";
&usage;
}
unless ( open(OUT, ">$out_file") ) {
print "\nGot a bad output file: $out_file\n\n";
&usage;
}
print "Parameters:\ninput file = $in_file\nout file = $out_file\n\n";
#---------------------------------------------------------------------------------------------------------------------------
#The main event
#---------------------------------------------------------------------------------------------------------------------------
while (<IN>) {
$line = $_;
$line =~ s/\r//g;
print OUT "$line";
}
close(IN);
close(OUT);
#-----------------------------------------------------------------------
sub usage {
print "\nUSAGE: ./remove_carriage_returns.pl\n\n";
print "Parameters:\n";
print "-i <input file>\t\tA file\n";
print "-o <output file>\tThe same file, with any annoying carriage returns removed.\n\n";
print "This script takes a file and creates a copy of the file with the carriage returns removed. Essentially, it converts a Windows style text file to a Linux/UNIX style text file.\n\n";
print "Jennifer Meneghin\n";
print "May 18, 2011\n\n";
exit;
}