在外壳中将ANSI转换为UTF-8 [英] Converting ANSI to UTF-8 in shell

查看:132
本文介绍了在外壳中将ANSI转换为UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个解析器(1 csv至3 csv)脚本,但遇到了问题. 我是法国人,因此在我的语言中我有类似é è à ....

I'm 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: é è à ....

一个客户向我发送了一个csv文件,Linux将该文件识别为"unknown-8bit"(我猜是ansi).

A customer sent me a csv file that Linux recognizes as "unknown-8bit" (ansi I guess).

在我的脚本中,我正在编写3个新的csv文件.但是ViM将它们创建为ISO latin1,因为它与输入中的内容很接近,但是我的é,è,à...坏了.我需要UTF-8.

In my script, I'm writing 3 new csv files. But ViM creates them as ISO latin1 because it's close to what it got in the entry, but my é,è,à... are broken. I need UTF-8.

所以我试图将第一个ANSI csv转换为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

问题是它破坏了我的CSV.现在只有一行.但是我的特殊字符还可以.有没有一种方法可以将ANSI转换为UTF-8并保留我的行?

The problem is that it breaks my CSV. It's now on only one row. But my special chars are ok. Is there a way to convert ANSI to UTF-8 and keeping my rows?

推荐答案

将输出放入另一个文件.不要覆盖旧版本.

Put the output into another file. Don't overwrite the old one.

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

iconv在读取和写入同一文件时失败.

iconv fails when reading and writing to the same file.

这篇关于在外壳中将ANSI转换为UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆