linux already has a command "dos2unix" which fixes the line endings.
In reply to Re: Remove ^M using script by eric256 in thread Remove ^M using script by Anonymous Monk