In my use case, I have a lot of text files containing invalid characters. When I search through those files, e.g.

grep "some text" /home/bla/blubb/* | xargs editor_of_your_choise

I'm getting the issue that whenever a file is opened containing any invalid characters, there is a popup in the editor.

For gedit:

There was a problem opening the file foo.txt

The file you opened has some invalic characters. If you continue editing this file you could corrupt this document.

In gedit's case showing three buttons, Retry, Edit Anyway, X. I have to use the mouse to press Edit Anyway, which is really annoying, if you have to do it for every file separately. Until I do it, the editor is blocked.

With Kate, it only allows me to use the file in a read-only state.

Is there a way to open the files forced to edit right away?

  • It seems that the default encoding that gedit is expecting and the encoding of the files you are grepping are not the same. Do you know what the encoding is of the files you are grepping? I assume it is not utf-8 (you can check with isutf8 from the moreutils package). – ozzy Jan 12 at 15:24
  • If you have no clue about the character encoding of your files you could guess with chardet or file -i as suggested here. – ozzy Jan 12 at 15:56
  • @ozzy actually its supposed to be UTF-8, however the characters not displayed correctly are 'ä', 'ü', 'ö' which are covered by UTF-8. eg. 'ä' is U+00E4, if I open the file with gedit the word, containing the character, is displayed as "st\E4rker" . So I'm a little bit confused cause the editor shows the escape \ followed by the UTF-8 HEX value – aldr Jan 14 at 16:55

Your Answer

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

Browse other questions tagged or ask your own question.