linux - 如何从文本文件中删除非 UTF-8 字符

我有一堆用 utf-8 编码的阿拉伯语、英语、俄语文件。尝试使用 Perl 脚本处理这些文件时,出现此错误:

Malformed UTF-8 character (fatal)

手动检查这些文件的内容,我发现其中有一些奇怪的字符。 现在我正在寻找一种方法来自动从文件中删除这些字符。

还有办法吗?

最佳答案

这个命令:

iconv -f utf-8 -t utf-8 -c file.txt

将清理您的 UTF-8 文件,跳过所有无效字符。

-f is the source format
-t the target format
-c skips any invalid sequence

https://stackoverflow.com/questions/12999651/

相关文章:

linux - Linux内核中浮点的使用

python - 如何从生成器构建 numpy 数组?

linux - 了解 Linux oom-killer 的日志

python - 为什么这个 Python 代码段中允许使用分号?

linux - Bash 中的多线程

python - 删除字符串的第一个字符

python - 如何在 Python 中使用方法重载?

python - 我如何告诉 matplotlib 我完成了一个情节?

python - 如何为子图设置公共(public)轴标签

linux - grep 不作为正则表达式