Sometimes, while moving text files from a MS Windows system to a Unix one, we can find a ^M character at the end of each file’s line.
This happens especially when the original files have been modified in MS Windows and then moved to Unix.
A new line in MS Windows is interpreted as a CRLF (Carriage Return, Line Feed) with Hex code 0D0A, while in Unix as a LF, Hex code 0A.
So that ^M is just the ASCII translation of the exceeding CR, 0D.
In Unix we can use the dos2unix utility in order to convert DOS text files to Unix.
The only problem of this utility is that you cannot overwrite directly the file, but you have to redirect the output to a new file and then replace the original one:
$> dos2unix input.txt > output.txt $> rm input.txt $> mv output.txt input.txt
You can imagine how could be nasty when you have to convert more than one file in the same directory.
Well, I have been googling for a while to find a solution and finally I have found very useful the following command:
find . -type f -exec dos2unix {} {} \;
By using the command above you can convert all the files within a directory in one shot!
