What my puzzle file!, How to remove special characters ??

My application generate file but it have special characters in these file.
I would like to clear special characters by vi editor and not use

cat /dev/null > to_file

I try to remove characters manually, but I'm can not!

root@MyHost /tmp> ls -l puzzle.txt

-rw-r--r--    1 root     system            3 Mar 28 10:37 puzzle.txt
root@MyHost /tmp> 
root@MyHost /tmp> cat -v puzzle.txt
root@MyHost /tmp> 

-- After remove it by vi (I press x for 3 times because it have 3 char right?) --

root@MyHost /tmp> wc puzzle.txt
       1       0       1 puzzle.txt
root@MyHost /tmp> cat -v puzzle.txt

root@MyHost /tmp> ls -l puzzle.txt
-rw-r--r--    1 root     system            1 Mar 28 10:55 puzzle.txt
root@MyHost /tmp> 

How I remove special chars???
you can try from attachement [NO Virus]

You could try to remove all special characters like this:

LANG=C tr -d '\200-\377' < puzzle.txt > puzzle.gone
1 Like

Oh! Thank you Scrutinizer,

But It will be effect with non-english alphabet too.

I couldn't download puzzle.txt so cannot be 100% sure. But the other proposed solution did NOT seem to work when I tried it on a small test file I made. I think this will get rid of all special characters, and adjust to your locale:

tr -cd '[:print:]\n' < puzzle.txt

The short answer is: you can't The single char "ls" shows is the End-of-File-character (literally a "^D") and it isn't possible with "vi" to delete it. In fact "vi" will even append such a EOF char to a file if it was missing.

Generate a file with "touch", it will have 0 characters. Now open this in "vi", write some text, delete it completely (this way "vi" thinks you have changed the file, do NOT use the undo-function) and save the file. You will notice that it has also 1 character in it - the EOF char.

I hope this helps.

bakunin

Sorry, but no. UNIX text files do not have an End-of-File character. Each line in a text file is terminated by a <newline> character. If you have a file open in vi and issue the commands:

:1,$d
:w file

(which deletes all lines in the file), the size of file will be 0 bytes.

If you have exactly one line in a file and you edit it with vi and delete all of the characters on the line by repeatedly executing the x command until the line is empty and then issue the command:
:w file
then the size of file will be 1 byte because you didn't delete the line, you just deleted the characters on the line preceding the terminating <newline> character.

The current line (including the terminating <newline> character can also be deleted in vi with the dd command.

2 Likes