I just had a power failure while I was working on a text file (specifically a latex .tex file). I had been saving regularly - so wasn't too worried about lost work. But now I can't actually use the file at all - if I open it in gedit, it's all gobbledigook, with the following error message:

There was a problem opening the file "[...].tex”. The file you opened has some invalid characters. If you continue editing this file you could corrupt this document. You can also choose another character encoding and try again.

(It was on UTF-8 - tried the other option to no avail)

Is there anyway to recover the file? Not the work I didn't save - but the entire file as it was before saving?

  • If the answer is not working for you please PM me. – Rinzwind Feb 25 '16 at 7:58

You have NUL values in your file (due to the power failure).

tr < {original_file} -d '\000' > {backupfile}

will remove the NUL values from {original_file} while creating a {backupfile}.

Check {backupfile} and confirm it is correct before deleting {original_file}.

If you do

file {original_file}

it probably will tell you it is a "binary file" and not a "text file".

  • 1
    Thanks - unfortunately that didn't work. Note file {original_file} actually returned 'data' – djmac Feb 25 '16 at 22:55

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.