Removing ^M Characters

April 22, 2022

You’re here because you have something like the above in your text files, and it’s driving you towards violence.

The universe sent you here so I can help you. You’re welcome.

The prescribed fix is this:

sed -e 's/^M//'

If that worked you wouldn’t be here. The actual fix is this:

tr -d '\r'

Bonus on this one: it actually works!

Now fix your file and go get some air.

Notes

  1. From Vim you can do the following as an ex command to get the same result within a file: :%!tr -d '\r'

supporting = loving

Since 1999 I've been creating ad-free technical tutorials and essays here. It's a one-person effort that's also my life and livelihood. If it makes your day more livable in any way, please consider supporting the work with a monthly or one-time donation. Your support means a lot to me, and makes all the difference. 🫶🏼