Wednesday, January 18, 2012

Converting line endings on the cheap

You're at a client's PC, installing some scripts and need to edit a text file. Of course your client has no real editor, just that stupid notepad.exe! And then you notice: All the line endings are wrong, that is, they're LF (unix convention) as opposed to CR-LF (dos convention). That is because you do have a real editor, and so does the other guy working on that file and one of you was not working on windows, because it's only an OS, right? A tool, not a religion.

Not religous either: What escapes your mouth when you are confronted with a single line of script and black box characters laughing at you where line breaks should be.

Now, users of cygwin are probably familiar with a myriad of tools (e.g. dos2unix.exe) to convert from dos line endings to unix line endings. You might be able to get tr to work for you too. Or you could just open the file in your trusty real editor and type away.

But your client has none of this installed.

What your client does have installed, is MS Word. Seriously. I'm going to use MS Word now. This is how:

  1. open the script/text file in notepad
  2. select all text, copy it to the clipboard ([CTRL]+[A], [CTRL]+[C])
  3. open a blank document in MS Word
  4. paste from the clipboard ([CTRL]+[V])
  5. select all text in MS Word, copy it to the clipboard ([CTRL]+[A], [CTRL]+[C])
  6. paste over (replacing) the selection in notepad ([CTRL]+[V])
  7. close MS Word and wash your hands to get rid of the dirty hack feeling...