Mac OS X TextEdit doesn’t display NULLs!

Mac OS X TextEdit doesn’t display NULLs!

We just had a real hair-puller of a problem so thought we'd blog about it here just in case someone else sees something similar. We had been sent a text file (.sql) of SQL Server 'CREATE TABLE' statements that we were manually converting to Oracle syntax just using TextEdit (OK, I know there are better editors but it was a small job and TextEdit was fine).


Our first problems occurred trying to edit the file when it appeared like the Mac's keyboard was broken.  We kept having to press the delete and cursor keys repeatedly to move around make the edits.  This seemed weird but we did the normal stuff like rebooting, updating to the latest OS X, swapping USB ports, checking the console etc but nothing looked amiss so kind of 'lived with it' as it wasn't a big deal.

Then we decided to run the script via SQLDeveloper and immediately noticed that our file wasn't syntax highlighted.  Weird?!   Trying various other editors (BBEdit, TextMate, TextPad on Windows) all showed the same problem - no syntax highlighting.  Then we noticed in TextMate that there were what appeared be spaces between every character.  Further examination using a hex editor showed that there was a NULL character (\0) in between every single character of the file!!

No wonder we had to press delete twice to do anything in TextEdit, and no wonder our syntax wasn't highlighted!

The next problem was how to remove the NULLs which is not as easy as it sounds.  However a variation on the blog entry below using 'tr' saved the day and now it is all much as it should be :

$ tr -d '\0' < tables.sql > tables2.sql

Hope this helps someone! 

UPDATE : we have now switched to TextMate for all text editing.  We love the fact we can run Shell scripts and SQL scripts directly from the environment using 'bundles'.  For those switching from TextPad on Windows, TextMate is a pretty good choice.


Comments (0)


Add a Comment

Please login to comment.