I recently ran into this same issue. I wrote the following short script to fix it. I don't know if it will work with everything, but it has for everything I have given it. Just supply the info it asks for, and it will create the FIXED file for you.
#!/usr/bin/perl -w
use strict;
use warnings;
my $FILE;
my $DST;
my $filename;
print("What file do you want to remove the trailing Carrige Returns fr
+om:");
while($filename=<STDIN>){
chomp($filename);
last;
}
open (FILE, '<', $filename) or die "Failed to open file:$!";
open (DST, '>', "FIXED".$filename) or die "Failed to open fix file:$!"
+;
while (<FILE>){
if($_ =~ /\r$/){
s/\r//;
print DST $_;
}
else{
print DST $_;
}
}
print("The file $filename has been fixed. The new file name is FIXED".
+$filename.".\n");
close FILE;
I am sure there are improvements that could be made, but it was a nice study on input output and basic regex.
I found that the ^M is indeed the same as a \r as is mentioned a couple of times above. This script just replaces it with nothing, essentially deleting it.
Cheers.