如何读取使用awk的不同编码的文件吗? [英] How to read files with different encodings using Awk?

查看:621
本文介绍了如何读取使用awk的不同编码的文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何正确在awk中比UTF8其他编码读取文件?

How can I correctly read files in encodings other than UTF8 in Awk?

我在希伯来文/ Windows的-1255编码的文件。
一个简单的{打印$ 0} AWK打印的东西一样。
我怎样才能使它正确地读取?

I have a file in Hebrew/Windows-1255 encoding. A simple {print $0} awk prints stuff like �. how can I make it read correctly?

推荐答案

AWK本身并不具备处理不同编码的支持。这将履行在环境中指定的语言环境,但你最好的选择是跨code输入到正确的编码交给其关闭,以AWK之前。

awk itself doesn't have any support for handling different encodings. It will honor the locale specified in the environment, but your best bet is to transcode the input to the proper encoding before handing it off to awk.

-f是你想从转换格式,-t是目标格式,并在其中prematurely终止的iconv的经营任何无效字符-c跳过。当然--help将给出更多的细节。

-f is the format you want to convert from, -t is the target format, and -c skips over any invalid characters which prematurely terminate iconv's operation. Of course --help will give more details.

iconv -c -f cp1255 -t utf8 somefile | awk ...

这篇关于如何读取使用awk的不同编码的文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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