Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing ^M from a csv file

Tags:

bash

I have a problem when I try to remove ^M from a csv

When I type vim or vi file.csv, I get

A, TK,2015-04-06,14.4^M,14.7,10.0,0.0,54.0^M,13.3^M,135.0^M,33.8
B, NV,2015-04-06,14.4^M,14.7,5.4,0.0,47.0^M,14.8^M,97.0^M,31.3

I have tried with

tr -d '^M' < file.csv > file2.csv

But it doesn't remove, also with sed.

like image 277
Enric Agud Pique Avatar asked Apr 06 '15 14:04

Enric Agud Pique


1 Answers

You could use dos2unix command which is provided to do that.

Using GNU/sed just for fun :

sed -i -e "s/\r//g" file

Using tr :

tr -d '\r' <file1 >file2
like image 129
Idriss Neumann Avatar answered Sep 18 '22 11:09

Idriss Neumann