Andrew Latham aka lathama, gringo malvado

Removing Microsoft end of line characters

Developers on various platforms can often unknowingly introduce encoding issues on files. Here is a solution to one problem.

Simple one liner to remove all ^M line returns from files in a directory. I use this on an Open Source project I work on mainly for PHP files. Type "CTRL v" then "CTRL m" to get the system ^M char. The character will not copy and paste. The filter for SVN is optional and insert CVS or git for your SCM of choice.

grep -IUrl "^M" * | grep -v svn | xargs sed -i 's/^M$//'

Easy! Search the directory recursively. Filter out the SVN files. Run SED against the files in the list.

Written by Andrew Latham on Tuesday March 17, 2015
Permalink -

« Python CLI Webserver - Web Comics »