Last Updated: February 25, 2016
·
977
· magnetikonline

Finding pesky \r\n source files

LIke many developers, having come from a Windows environment in a deep, dark time long, long ago, getting rid of \r\n line endings from source has become a personal quest of mine, usually found in my older projects (and sometimes in the odd piece of 3rd party code).

The following alias is handy for this quest of mine:

alias findcrlf='grep -lIUrP "\r" .'

Coupling this with Git (you use Git, right?) is the following core config setting to help things along:

git config --global core.autocrlf "input"

Note: -P means grep uses PCRE for matching, which grep implementations often list as "highly experimental", but I haven't seen any issues personally with this.

Happy \r\n squashin!