5

I'm doing a research project in NLP. For that I have to analyze a unicode (Sinhala) text file of around 10mb and it opens in Google docs. But when I try to open it from gedit I'm getting this error

Unexpected error: Invalid byte sequence in conversion input

So, I followed this similar question and tried the second answer which suggests running this command in terminal:

gsettings set org.gnome.gedit.preferences.encodings auto-detected "['UTF-8', 'CURRENT', 'ISO-8859-15', 'UTF-16']"

I got this result in the terminal:

GLib-GIO-Message: Using the 'memory' GSettings backend.  Your settings will not be saved or shared with other applications.
No such key “auto-detected”

So, no success. When I try to open the file in gedit, I'm getting the same error. How can I fix this? How can I open this file in gedit?

6

I am not sure what the cause of the problem is, but I was able to reproduce it on my system.

Experimentally, I ran dos2unix on the file and the output said it was a UTF-16LE file. For the curious, LE means little endian. After dos2unix had converted the file to UTF-8 format, I was able to open it with Gedit.

sudo apt install dos2unix
dos2unix -n oldfile newfile
gedit newfile

I used the -n flag to avoid overwriting the original file. Replace oldfile with the original filename and newfile with whatever you want the new file to be called. Use tab completion (type the start of the filename and press tab and the full name should appear) or ' quotes if your filename has spaces or other special characters.

As a sidenote, I was able to open the file without converting it using Pluma, a text editor based on Gedit, so I suspect that this may be a bug in Gedit. Passing --encoding UTF-16LE or --encoding UTF-16 to Gedit when opening the file did not help.

  • 2
    +1 Excellent work! If it may be a bug, shouldn't we report it? – dessert Apr 14 '18 at 11:17
  • Thank you very much, it worked. First I though it was an error with the text file as I got some other text files which opened from gedit without any issue. – Thidasa Pankaja Apr 14 '18 at 11:18
  • @PankajaParanavitharana you are very welcome. Sorry not to be more illuminating about the cause though! – Zanna Apr 14 '18 at 11:20
  • 2
    @dessert yes, probably! I shall try to investigate further when I have time – Zanna Apr 14 '18 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.