Removing Windows Carriage Returns in Vim
I’ve been learning a ton working on a project with Jim and Michael this past month and I have lots of blogging to catch up on- so here’s tip #1.
We’ve received several CSV files from our client that we’re using for seed data- and oftentimes we’ve had to do a little cleaning before importing them (my next tip will be the simple script to use a CSV for seed data).
Removing Windows Carriage Returns from a Microsoft Excel generated CSV is a simple enough problem that I’m sure many people already know the answer (or have an alternate solution), but it’s also a common enough problem that I wanted to write it down. Thanks to Jim for quickly tracking down the solution for me.
If you’re using Vim or MacVim you can remove these with a simple replace:
:%s/^M/\r/g
But in order to generate the “^M” that you want to match you need to use ctrl-v to make the “^” and ctrl-m to make the “M”.