Advertisements

Remove ^M (Control-M) characters from a file in Unix

When checking my /etc/multipath.conf file, there was a lot of hidden characters ^M at the end of lines

root@linux:~ # cat -vet /etc/multipath.conf

To remove them, use tr and redirect the output to a new file.

root@linux:~ # tr -d ‘\015’ < /tmp/multipath.conf

Check the file and if everything is okay, replace the original file

root@linux:~ # tr -d ‘\015’ < /tmp/multipath.conf > /tmp/multipath.conf.new
root@linux:~ # cat -vet /tmp/multipath2.conf.new
root@linux:~ # mv /tmp/multipath2.conf.new /tmp/multipath.conf

Advertisements
%d bloggers like this: