There are many ways to skin a cat, here are a few:
Cleaning ^M's from DOS files
Example file with ^M's
# vi /tmp/hosts.dos
194.19.11.10 bill bill.foo.com^M
10.19.11.203 sorry sorry.foo.com^M
10.19.11.161 happy happy.foo.com^M
happy happy.foo.com^M
There are a couple of ways that the Ctrl-M ( ^M) can be stripped out of the
file. The first is the tr command, which is used to translate characters. It
is possible to tell tr to delete all Ctrl-M characters.
# tr -d "\015" < /tmp/hosts.dos > /tmp/hosts.unix
In this tr command, you delete ( -d) all occurrences of the \015 or Ctrl-M
character from the file /tmp/hosts.dos and rewrite the output to
/tmp/hosts.unix file. Another way to strip the Ctrl-M character is to pass
the file through sed and have it perform a substitution:
# sed 's/^V^M//g' /tmp/hosts.dos > /tmp/hosts.unix
In this version, sed processes the file /tmp/hosts.dos searching for all
occurrences of the Ctrl-M character. When it finds one, it performs a
substitution of the character. In this case, you can swap the Ctrl-M with
null and output the results into the /tmp/hosts.unix file.
The sed command can also be used from within the vi editor. The vi editor
has two modes: the insert mode and the command mode. From within the command
mode, sed can be executed to perform the substitution.
vi /tmp/hosts.dos
When inside the vi editor, make sure you are in the command mode by pressing
the Esc key. Pressing the colon (

key allows you to input the sed
command.
:%s/^V^M//g
This command behaves the same as using the sed command from a UNIX shell. It
searches for all occurrences of the Ctrl-M character. When it finds one, it
substitutes the character with nothing. You can then continue working in the
file if you have more changes to make.
Good Luck
Laurie.