I had a big issue with this while trying to get a flat file into Oracle. I tried using vi and sed, and ultimately came upon a solution using strings and tr.
Here is my shell script:
#make a backup
cp $1 $1.orig
#Strip out nulls.
tr -d �\0 < $1.orig > $1.temp
#Strip out other unprintable characters
strings $1.temp > $1
#Remove temp file.
rm $1.temp
#Fix permissions. (You may not need this for your application)
chmod 744 $1
Have you misunderstood vi's "set list". What it does is print a "$" sign at the end of each line (and show tabs as ^I). The $ sign isn't in the file itself it is just displayed to make it easier for you to spot things like trailing spaces at the end of lines.
This is a very small issue but create big problems in unix.I have faced this issue several times and found dos2unix command most easiest way.Try this command
dos2unix filename filename
keeping same filename will remove the ^M character from file.
Yes, Hitori, you are right. I forgot to add de "$"
My sed command would remove ^M wherever it is. The "g" is not necessary because it means "in the whole line".
I'm sorry.