Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a text file. I created the content of the text file by copying from some webpage into it. During the creation, I was completely under gedit. I then saved the file and exited gedit. But since then, I haven't been able to open the file in gedit (although I could open it in Emacs). I tried to open it in gedit, but fails because "Unexpected error: Invalid byte sequence in conversion input".

  1. How shall I open such a file successfully, if without changing the content of the file?
  2. I guess there are some "bad" characters in it, and want to see what they are and remove them if they are not important. How shall I identify those culprit characters?

Thanks!

share|improve this question
1  
Try opening it with vim - it will open anything, I believe. It may warn you if it's got binary data, but I think it will still open it. If you need to edit the file, and totally don't know how to use vim, type this to get help: :help tutorial –  Marty Fried Jul 7 '12 at 20:06
    
This happens for me, too, with Quantal. Files that could previously (in Precise) be opened by gEdit are now showing this error instead. bugs.launchpad.net/ubuntu/+source/gedit/+bug/1067915 –  Matt White Nov 12 '12 at 15:52
add comment

1 Answer

I’ve been facing the same issue. For me the problem was that the encoding of the file had changed since it was last opened with Gedit (from WINDOWS-1252 to UTF-8). As I had manually set the encoding when first opening the file, Gedit had saved this information and tried to reuse it the next time I opened the file after the encoding change; this resulted in said error message.

To fix the problem, I had to remove the saved encoding information from the gvfs metadata like so:

gvfs-set-attribute --type unset MY_FILE.txt 'metadata::gedit-encoding'

You can always find out what Gedit has saved about a particular file:

gvfs-info MY_FILE.txt | grep 'metadata::gedit'

For example, before issuing the above command, the output for my file was this:

  metadata::gedit-encoding: WINDOWS-1252
  metadata::gedit-position: 0
  metadata::gedit-spell-language: de_DE

After I had removed the encoding attribute, the output was just this:

  metadata::gedit-position: 0
  metadata::gedit-spell-language: de_DE
share|improve this answer
    
Thanks Chiki! For gvfs-info MY_FILE.txt | grep 'metadata::gedit', my plain text file returns metadata::gedit-position: 8189, nothing about gedit-encoding. So gvfs-set-attribute --type unset MY_FILE.txt 'metadata::gedit-encoding' doesn't change any attribute. I still encountered the same error as before. –  Tim Apr 12 '13 at 20:34
    
@Tim Ok, then we are probably facing different issues. What might help you track down your issue is this: you could copy the content of your text file into a new file via a command line (to hopefully circumvent gvfs and friends), e.g., with cat MY_FILE.txt > MY_NEW_FILE.txt. Then try to open MY_NEW_FILE.txt in Gedit. If the error persists, then it’s probably really a content problem. Otherwise, there is some (other) metadata problem. –  Chriki Apr 13 '13 at 7:18
    
the problem persists after cat MY_FILE.txt > MY_NEW_FILE.txt. So it might be because of some strange characters in the text file. I created the content of the text file by copying from some webpage into it. During the creation, I was completely under gedit. I then saved the file and exited gedit. But since then, I haven't been able to open the file in gedit (although I could open it in Emacs). Do you happen to know what other solutions I can try, and/or how to find out those characters? –  Tim Apr 13 '13 at 12:15
    
@Tim Perhaps the file has an unusual encoding which differs from your default system encoding (probably UTF-8). You can try to auto-detect the encoding with chardet MY_FILE.txt (chardet is available in the package python-chardet). Then you could convert the file to UTF-8, e.g., via iconv -f MY_FILE_ENCODING -t utf-8 MY_FILE.txt > MY_NEW_FILE.txt. Hopefully MY_NEW_FILE.txt can then be opened by Gedit. An alternative to converting the encoding would be to go to Gedit’s file ”Open” dialog and to manually select the encoding at the bottom of the dialog before actually opening the file. –  Chriki Apr 14 '13 at 8:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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