🦊

remove CTRL-M (^M) characters

From SUSE Support’s How to remove CTRL-M (^M) characters from a file in Linux.

^M represent the ACII control character sequence <CR><LF>/0xd 0xa. It represents new lines on DOS/Windows while Unix based systems use <LF>. This can also occur when overriding $TERM over ssh.

view

cat -v filename

^M appears in git commits.

removal methods

There are many ways to replace 0xd 0xa with 0xa.

vi/vim

Inside vi ESC mode type: :%s/^M//g

Note: To enter ^M, type CTRL-V + M.

dos2unix

dos2unix filename

sed

sed -e "s/\r//g" file > newfile

perl

perl -p -e 's/\r//g' file > newfile