LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Nautilus and Gedit fail to open text files (https://www.linuxquestions.org/questions/linux-software-2/nautilus-and-gedit-fail-to-open-text-files-310288/)

zarkon 04-06-2005 06:09 AM

Nautilus and Gedit fail to open text files
 
I have a whole load of text files that I saved when I used MS Windows but I can't open then in Nautilus or Gedit - both complain about invalid utf-8 data.

I can open them in Konqueror and Kedit and can see the invalid data - it's one character at the end of the file which Konqueror / Kedit represents as a square. If I delete that character then Nautilus and Gedit can open the files up.

Is this a bug in Nautilus / Gedit or am I missing some fonts? Why does Konqueror / Kedit cope when the others can't?

I'm using RHEL v3 on a IBM T41 laptop.

Cheers

homey 04-06-2005 08:16 AM

I don't know why some editors are able to open them and others are not.
You are right about the character in those files and quite often I hear about it when someone tries to run a script which was created in windows notepad. They get this kind of error....
# ./test
: bad interpreter: No such file or directory

Here is a script which may help you get rid of the problem. For example, the text files are in /home/images...
Code:

#!/bin/bash
cd /home/images
for i in `ls *.txt` ; do
cat $i | tr -d '\015' > $i
done


zarkon 04-06-2005 08:29 AM

Quote:

Originally posted by homey
Here is a script which may help you get rid of the problem. For example, the text files are in /home/images...
Thanks for that.

it kind of works - the test file I used can now be opened but half of the real text is missing!!

Alan

homey 04-06-2005 10:00 AM

I'm glad you are smart and use a test file to see if it works. :)

Maybe it's because I tried to overwrite an open file in this line...
cat $i | tr -d '\015' > $i

Edit: this one is a better idea if you have spaces in the file name...
Code:

#!/bin/bash

mkdir /home/tmp 2> /dev/null
cd /home/images

for i in *.txt ; do
cat "$i" | tr -d '\015' > "/home/tmp/$i"
done
mv -v /home/tmp/*.txt /home/images



All times are GMT -5. The time now is 04:31 PM.