As already explained, Windows programs like to terminate lines with CRLF, i.e. \r\n
instead of the Unix/Linux standard \n
. Since I don't need all the features of dos2unix
I replaced it by adding the following to my ~/.bashrc
which removes the \r
:
function win2unix() {
tmp=$(mktemp) && tr -d '\r' < $1 > $tmp && mv $tmp $1
}
Now when I want to get rid of those ^M
characters created e.g. when I export a CSV file from Excel or Calc, I can just do something like:
win2unix filename.csv
You could also use sed
or something else, of course. By the way, I use cat -e $filename
to visualize the ^M
endings.