![]() |
|< 1 2 >| | ![]() |
20 Einträge, 2 Seiten |
C:\> perl dos2unix.pl < dostext.txt > unixtext.txt
C:\> perl dos2unix.pl dostext.txt > unixtext.txt # klappt nicht!
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
my (@newLine) = &AnalyzeFileEol($infile);
my $newLine = join("", map { chr(hex($_)) } @newline;
local $/ = $newLine;
# ------------------------------------------------------------
sub AnalyzeFileEol {
my ($file) = shift;
my $eol = chr(10);
unless (open (FH, "<", $file)) {
die "Error: couldn't read file '$file': $!\n";
} # unless
my @chars = ();
while (defined (my $chr = getc(FH))) {
my $hex = sprintf("%02X", ord($chr));
if ($hex eq '0D') {
my $next = sprintf("%02X", ord(getc(FH)));
if ($next eq '0A') { close (FH);
print "Newline format: Dos: $hex $next\n";
return ($hex,$next);
} # if
else { close (FH);
print "Newline format: Mac: $hex\n";
return ($hex);
} # else
} # if
elsif ($hex eq '0A') { close (FH);
print "Newline format: Unix: $hex\n";
return ($hex);
} # elsif
} # while
die "Error: couldn't find out file format\n";
close (FH);
return;
} # AnalyzeFile
# ------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
my (@newLine) = &AnalyzeFileEol($infile);
my $newLine = join("", map { chr(hex($_)) } @newline;
local $/ = $newLine;
# ------------------------------------------------------------
sub AnalyzeFileEol {
my ($file) = shift;
my $eol = chr(10);
unless (open (FH, "<", $file)) {
die "Error: couldn't read file '$file': $!\n";
} # unless
my @chars = ();
while (defined (my $chr = getc(FH))) {
my $hex = sprintf("%02X", ord($chr));
if ($hex eq '0D') {
[...]
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
#!/usr/bin/perl
use strict;
use warnings;
my $filename = shift;
{
local $/ = LineSeparator($filename);
# mach was mit der Datei
}
exit 0;
############################################################
sub LineSeparator {
my ($file) = @_;
open (my $infile_h, '<', $file) or die "could not open '$file' for reading: $!";
binmode $infile_h;
my $eol = '';
my $format = 'unknown';
while (defined (my $chr = ord getc($infile_h))) {
if ($chr == 0x0D) {
$chr = ord getc($infile_h);
if ($chr == 0x0A) {
$format = 'DOS';
$eol = "\x0D\x0A";
} else {
$format = 'MacOS 9 or earlier';
$eol = "\x0D";
}
last;
} elsif ($chr == 0x0A) {
$format = 'UNIX';
$eol = "\x0A";
last;
}
}
close $infile_h;
print STDERR "Line terminator format: $format\n";
return $eol;
}
![]() |
|< 1 2 >| | ![]() |
20 Einträge, 2 Seiten |