as/400 如何识别文件的编码? cat 正确打印两种不同的编码

how an as/400 recognizes the encoding of a file? cat prints correctly two different encodings

我在QSHELL中cat了两个相同文本不同编码的文件,都打印了相同的内容,看(hell.txt是EBCDIC,hellascii.txt是ASCII):

cat hellascii.txt
hello @@@@@@@

cat hell.txt
hello @@@@@@@

od -x hell.txt
0000000 4040 4040 8885 9393 9640 7c7c 7c7c 7c7c
0000020 7c25
0000022

od -x hellascii.txt
0000000 2020 2020 6865 6c6c 6f20 4040 4040 4040
0000020 4000
0000021

在我的笔记本电脑中,在 linux 或 mac 中,EBCDIC 编码显示其他字符看起来很乱。 as400 中的 unix 如何正确打印两者?我没有看到任何内容,例如指示编码的文件头。例如,0x40 在 ascii 中是 @,在 EBCDIC 中是 space,但是 cat 在 hell.txt 中正确打印 0x40 为 space,在 hellascii.txt 中正确打印为 @.

在 IBM i 上,系统会跟踪分配给每个 IFS 文件的 CCSID。您可以使用 od 的 -C 选项查看 CCSID。这是一个例子。

$ od -tx -C helloascii.txt
helloascii.txt CCSID = 819
0000000  68692074 68657265 0a000000
0000011
$ od -tx -C helloebcdic.txt
helloebcdic.txt CCSID = 256
0000000  888940a3 88859985 25000000
0000011

您可以使用 touch 的 -C 选项分配新文件的 CCSID。这是我创建上面使用的文件的方式。

$ touch -C 819 helloascii.txt
$ echo 'hi there' >> helloascii.txt
$ touch -C 256 helloebcdic.txt
$ echo 'hi there' >> helloebcdic.txt