How can I convert a Windows text file into a UniBasic text file?

The sample shell script below converts a Windows text file into a UniBasic text file. Make sure that the script is executable and you pass the name of file you want to convert. The DOS text file should not contain any non-ASCII characters.

Note: ^M in the script below is the carriage return character which may be entered in vi as control-v followed by carriage return.
MakeUBTextFile()
{
    sed 's/^M$//' $1 >ub$$.txt
    rm -f $1
    mv ub$$.txt $1
}

while [ "$#" -gt 0 ]
do
    MakeUBTextFile $1
    shift
done