0

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.

FedKad
  • 9,212
  • 7
  • 40
  • 79
  • 1
    I'm guessing here - but have you tried `iconv`? e.g. `iconv -f ISO-8859-9 -t utf-8//translit test-file` – steeldriver Mar 15 '19 at 11:09
  • No. I do not want to convert the output. I just want it to be displayed in correct format. The only solution I found out so far is to change the *Terminal*'s character *Encoding* to "_Turkish - ISO-8859-9_" (under *Compatibility*). Changing the locale seems to have no effect. – FedKad Mar 15 '19 at 15:41

1 Answers1

1

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.

$ file file.ISO-8859-9 
file.ISO-8859-9: ISO-8859 text

$ cat file.ISO-8859-9 
������������

$ iconv -f ISO-8859-9 -t utf-8//translit file.ISO-8859-9 
ğüşıöçĞÜŞİÖÇ
steeldriver
  • 131,985
  • 21
  • 239
  • 326
  • Thank you very much for the detailed explanation. I may need to create a short script or command alias to easily access the *iconv* command as you suggested. My initial thought of just changing the locale to something like `tr_TR.iso88599` seems be wrong. – FedKad Mar 15 '19 at 16:09