-
Notifications
You must be signed in to change notification settings - Fork 1
/
linendings
executable file
·42 lines (35 loc) · 1.05 KB
/
linendings
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
#!/usr/bin/perl
## ---------------------------------------------------------------- ##
## LINENDINGS
## ---------------------------------------------------------------- ##
## Converts text files to the specified line endings format.
##
## Author: T.R. Fullhart, kayos@kayos.org
## ---------------------------------------------------------------- ##
## Usage:
## $ linendings -[unix|dos|mac] file1 file2 ... fileN.,
## ---------------------------------------------------------------- ##
my $lineending = "\n";
my $type = shift @ARGV;
if( $type =~ /unix/ ) {
$lineending = "\012";
} elsif( $type =~ /dos/ ) {
$lineending = "\015\012";
} elsif( $type =~ /mac/ ) {
$lineending = "\015";
} else {
print "Usage: $0 --unix|--dos|--mac\n";
exit 1;
}
my @files = @ARGV;
for my $file ( @files ) {
open FILE, $file or next; # thanks turnstep
my @lines = <FILE>;
close FILE;
foreach my $i ( 0..$#lines ) {
$lines[$i] =~ s/(\012|\015\012?)/$lineending/g;
}
open FILE,">$file";
print FILE @lines;
close FILE;
}