In short: How can I display a file to the terminal that is not encoded in UTF-8?
Currently, I have a test file encoded in ISO-8859-9 and containing the following 12 characters:
ğüşıöçĞÜŞİÖÇ
The hex contents of the file is like this:
\F0\FC\FE\FD\F6\E7\D0\DC\DE\DD\D6\C7
When I try to display this file to the terminal, I get:
������������
I guess this is because, my current locale is defined like this:
$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_GB.UTF-8
LC_TIME=en_GB.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=en_GB.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=en_GB.UTF-8
LC_NAME=en_GB.UTF-8
LC_ADDRESS=en_GB.UTF-8
LC_TELEPHONE=en_GB.UTF-8
LC_MEASUREMENT=en_GB.UTF-8
LC_IDENTIFICATION=en_GB.UTF-8
LC_ALL=
However, I installed the Turkish locale to the system:
$ locale -a
C
C.UTF-8
en_GB
en_GB.iso88591
en_GB.iso885915
en_GB.utf8
en_US
en_US.iso88591
en_US.iso885915
en_US.utf8
POSIX
tr_TR
tr_TR.iso88599
tr_TR.utf8
turkish
So, I want to temporarily change the display language with the following:
$ export LC_ALL=tr_TR.iso88599
$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US
LC_CTYPE="tr_TR.iso88599"
LC_NUMERIC="tr_TR.iso88599"
LC_TIME="tr_TR.iso88599"
LC_COLLATE="tr_TR.iso88599"
LC_MONETARY="tr_TR.iso88599"
LC_MESSAGES="tr_TR.iso88599"
LC_PAPER="tr_TR.iso88599"
LC_NAME="tr_TR.iso88599"
LC_ADDRESS="tr_TR.iso88599"
LC_TELEPHONE="tr_TR.iso88599"
LC_MEASUREMENT="tr_TR.iso88599"
LC_IDENTIFICATION="tr_TR.iso88599"
LC_ALL=tr_TR.iso88599
$ cat a.txt
������������
But, I still get the question marks.
You can use the
iconv
utility (note: it does not convert the file in-place; the converted output is displayed in the terminal unless you redirect it elsewhere).Ex.