Removing ^M Characters

April 22, 2022
Daniel Miessler

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'

Reader-supported

For roughly 29.8115 years I've written here, ad-free—3,085 essays and tutorials and counting. If it's useful to you, a monthly or one-time donation keeps it going. 🫶🏼