Removing ^M Characters From Multiple Files
In my day job I find that I frequently need to remove those pesky '^M' line endings from text files that are transferred from one system to the other. Most of the time it is just one file that needs to be fixed so going into vi and typing
:%s/^M//g
solves the problem, but on occasion I might be confronted with performing this process on multiple files and sometimes recursively through many subdirectories. When that happens it becomes necessary to bring out the "big guns" and do:
$ for file in $(find /path/to/dir -type f); do
tr -d '\r' <$file >temp.$$ && mv temp.$$ $file
done
$
(BTW, to generate a ^M character using the PuTTY emulator is easy. Just press CTRL-^ followed by CTRL-M)
Of course, in Linux, UNIX and AIX shells there are many ways to skin a cat and this is just one of many possible solutions. This solution was found on a Daily Vim Blogspot site which has more very interesting tips & tutorials.