Text File Weirdness
Yesterday I was working on someone’s computer and I wanted to run a couple of SQL scripts. But the task, which should have taken mere minutes, took close to 45 minutes.
I downloaded a sql script from my website but any tool that I would use to run the script was failing. Even though I know the script was good.
When opening the script in Notepad it looked like this…
…when is should have looked like this.
To figure out what was wrong, Notepad++ too the rescue. Here is what each the file looks like in Notepad++…
Fortunately for me, Notepad++ is “smart enough” to not care what the Windows standard is. The trick is that Notepad++ is showing me that each line is being delimited with an ASCII Line Feed (LF) character. Windows expects lines in text files to be delimited with 2 ASCII characters, the Carriage Return and Line Feed (CRLF). In other words, it should like like this…
How to fix it.
To fix it I used Notepad++ Advanced find and replace fixture. Do CTRL-H (a windows standard keystroke, BTW, for opening the Find/Replace dialog in most programs.)
Here is what the dialog should look like in order to fix the file…
Notice at the bottom of the dialog I selected the Extended feature, which allows me to find and replace non-visible ASCII characters. Use \n to find Line Feed characters (think of “n” as meaning New Line) and use \r to find Carriage Returns (think of “r” as meaning Return.).
After doing the replace, not only would the file open correctly in Notepad but my SQL tools would run the script.
The next thing to figure out is how the file got munged. I suspect that the wonderful, new, free FTP client that I am using may have done it when I uploaded the file and that I need to tweak some setting next time I use it. Maybe my next post I can disclose the fix.
Hope this helps someone else. Enjoy.
PS In case you don’t realize it yet from this post…NOTEPAD++ ROCKS.
UPDATE – I discovered that it was not the FTP upload that was munging the file. It was the mere act of downloading it from the website. So now I am zipping scripts before putting them there.