How would I write this VIM command for `sed`?

I have a .csv with special characters that are wrecking an import I need to do.

In VIM, I discovered away to remove the special characters with :

:%s/\r//g

This removes ^M from some of my broken lines.

But I'd like to either write this into a bash script, or into my ruby script. So I was curious if there's a way I can perform this special character search and replace in either Bash or Ruby.

Searching for ^M does not work. And also you wouldn't see this character in any text editor except for VIM.

6

1 Answer

This works for me (Fedora 20, GNU sed 4.2.2):

sed -e 's/\r$//' <file-in> > <file-out>

(Replace <file-in> and <file-out> with your file names.) I use file to check the line endings.

4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like