2

Related question - except I'm moving from Windows to Ubuntu (don't need Windows notepad)

I am trying to open a text file using gedit/Ubuntu 16.04 that was created in Windows using the apparently notorious notepad. The invalid characters error message appears along with garbled characters. How do I see and edit this within Ubuntu?

Surveyor
  • 21
  • 1
  • 2

2 Answers2

4

Likely an unexpected encoding:

>cat ISO-8859-15.txt
d�j� emp�ch�

Thefile command can tell you the encoding used:

>file ISO-8859-15.txt 
ISO-8859-15.txt: ISO-8859 text

With this information you can use iconv to convert to another encoding (usually UTF-8):

iconv -f ISO-8859-15 -t UTF-8 -o UTF-8.txt ISO-8859-15.txt

Check:

>file UTF-8.txt 
UTF-8.txt: UTF-8 Unicode text
>cat UTF-8.txt 
déjà empêché
George Udosen
  • 37,534
xenoid
  • 5,759
1

Probably this has to do with a different character encoding (see https://en.wikipedia.org/wiki/Character_encoding) being used when the file was created, and the gedit editor is not able to guess that.

One way to solve it could be to try opening the file using some other program, like emacs or libreoffice -- from there you can then hopefully save the file using a character encoding that also gedit can handle.

You can try using the file command on different text files to try to detect what character encoding each file is using. Example:

$ echo ABC123 > test1.txt
$ echo ABCÅÄÖ > test2.txt
$ file test1.txt 
test1.txt: ASCII text
$ file test2.txt 
test2.txt: UTF-8 Unicode text
Elias
  • 2,159