The point is that if you run this on something like a *.wav or *.gz or *.zip file, etc, and the number of times you see "0x0A" is exactly equal to the number of times you see "CRLF", then it's extremely likely that this file has gone through a unix2dos conversion -- which would explain why playback has those annoying clicks, or why uncompression won't work, etc. -- and you should probably just delete it (don't even try to fix it).#!/usr/bin/perl use strict; die "$0 file2chk\n" unless @ARGV == 1 and -f $ARGV[0]; $/ = "\x0a"; # make sure we're "platform independent"! open( I, $ARGV[0] ) or die "$ARGV[0]: $!"; my $crlf; while (<I>) { if ( "\x0a" ne chop ) { # $. is incremented for the last record, $.--; # even when the file does not end with \x +0a } elsif ( "\x0d" eq chop ) { $crlf++; } } print "$ARGV[0] : $. \\x0A, $crlf CRLF\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Check for "unix2dos" (CRLF) in binary files
by Aristotle (Chancellor) on Sep 17, 2004 at 07:19 UTC | |
by graff (Chancellor) on Sep 17, 2004 at 07:34 UTC | |
by Aristotle (Chancellor) on Sep 17, 2004 at 07:55 UTC | |
by jfroebe (Parson) on Sep 23, 2004 at 16:16 UTC | |
by graff (Chancellor) on Sep 24, 2004 at 02:33 UTC |