Convert ANSI to UTF-8 in a Shell

I am making a parser (1 csv to 3 csv) script and I have a problem. I am French, so in my language I have letters like: รฉ รจ ร  ....

The client sent me a csv file that Linux recognizes as "unknown-8bit" (ansi, I think).

In my script I am writing 3 new csv files. But ViM creates them as ISO latin1 because it is close to what it got in the record, but my รฉ,รจ,ร ... broken. I need UTF-8.

So, I tried to convert the first ANSI csv to UTF-8:

 iconv -f "windows-1252" -t "UTF-8" import.csv -o import.csv 

The problem is that it crashes my CSV. Now this is just one line. But my special characters are fine. Is there a way to convert ANSI to UTF-8 and save my lines?

+8
bash shell csv utf-8 iconv
source share
1 answer

Put the output in another file. Do not overwrite the old one.

 iconv -f "windows-1252" -t "UTF-8" import.csv -o new_import.csv 

iconv does not work when reading and writing to the same file.

+20
source share

All Articles