How to remove the ^M characters in a file on FreeBSD?
This is simple:
There are multiple ways to do it. One is actually included in the FreeBSD-tips file:
So if you installed the “games” distribution, you get tips every time you log in. And once in a while the above tip will show up.
I had never used that one however, I had always used this one (which I modified) that I found here: http://sed.sourceforge.net/sed1line.txt
However, this one works with the
bash but not with the
This one worked on
csh but I am not sure if it is recommended as it assumes every line ends with ^M.
Anyway, I like how FreeBSD supports the -i parameter. Because if I am doing lots of files, I can have a script that does each file in a directory and then (of course I have a back up just in case) I can run sed -i.bak ‘s/.$//’ filename on each file and then do delete all .bak files so every file “appears to be” edited in place.