As I started to mention in this thread Checking for filetypes?:

I'm writing a script that will search files that contain certain keywords, and then output the line to a text file.

The problem I'm having is that the script is opening every type of file, including executables.

The script seems to work fine, as in it doesn't crash when it opens these types of files, but the problem I'm having is with the output.

When the script outputs text from some type of non-text-based file, I cannot open the file with gedit. It gives me the "gedit has not been able to detect the character encoding."

Can I force the script to output using a specific encoding so that I can open and read the output file in a text editor such as gedit?

The script itself will be run on Linux.



Gedit is going to use whatever locale the OS is set up for. I'm sure you can probably change the UTF for gedit alone, although I don't use it so don't know. You can also change the locale which would make the change system wide, but how you do this would depend on which distro you are using so it is best to ask that question on your distro's forum.