in reply to How to Detect Mixed File Line-Endings

G'day paul-s-,

Welcome to the monastery.

This solution, which requires Perl 5.10.0, will skip your Windows files and allow you to process the Unix files.

Given these files:

$ cat -vet pm_1070943_CRLF.txt text^M$ $ cat -vet pm_1070943_LF.txt text$

[Note: "cat -vet" shows special characters in files: '^M' = carriage return; '$' = newline]

This script:

#!/usr/bin/env perl use 5.010; use strict; use warnings; use autodie; for my $file (qw{pm_1070943_CRLF.txt pm_1070943_LF.txt}) { open my $fh, '<', $file; my $first_line = <$fh>; $first_line =~ /(\R)\z/; if ($1 eq "\x0D\x0A") { say "Skipping: $file"; } else { say "Processing: $file"; } }

[Note: '\R' is described in "perlrebackslash: Misc"]

Produces this output:

Skipping: pm_1070943_CRLF.txt Processing: pm_1070943_LF.txt

-- Ken