Showing posts with label ctrl-m. Show all posts
Showing posts with label ctrl-m. Show all posts

Wednesday, June 3, 2009

Recursively Replace Ctrl-M

Ctrl-M's are a plague inflicted upon programmers everywhere. I've mentioned a number of ways to deal with them in the past, and some readers have also contributed helpful advice as well. Today I ran into a situation where I needed to do a huge source diff on two different directory trees. My preprocessor happened to strip out all Ctrl-M leading to a bunch of false positives on files that differed. Some Google'ing around lead me to find this gem, which recursively strips Ctrl-M on all files within a given directory.


for file in $(find /path/to/dir -type f); do
tr -d '\r' <$file >temp.$$ && mv temp.$$ $file
done


In order to give credit where it's due, a user named blowtorch gave the tip at the following forum.