Nick's Tech Blog: Use sed to remove '^M' characters from a file

Pages

Friday, August 17, 2012

Use sed to remove '^M' characters from a file

Simple stuff, this post is here more as a reference than anything.

Problem

Windows puts '^M' characters throughout text files. I want to remove them.

Solution

The following commands will strip out the '^M' characters, and put the contents into a new file, then overwrite the original file.
sed -e s/^M//g oldfile.txt > newfile.txt
mv newfile.txt oldfile.txt
To get the '^M' character, type Ctrl+V,Ctrl+M

No comments:

Post a Comment