16-Apr-2013: Updated source code. Rewrite of post.
Everybody knows the old trick of converting a text file with Unix newlines (LF) to Windows line-endings (CR+LF):
more unix.txt > win.txt
more will wait for a keypress after scrolling 65,534 lines, even if output is redirected to a pipe or file.) But converting from Windows to Unix is a far more complicated affair. After searching failed to find any straightforward Batch solutions—apart from this meandering thread on DosTips—I cranked out
win2unix.cmd as outlined below.
From time to time, you may find yourself building up a file comprised of command output and snippets from other files. On these occasions, you will no doubt be using pipes and redirection, and commands such as
Which is all well and good except that you could easily run into trouble if some of the bits and pieces you're cobbling together end with a newline while others don't. For instance,
type will join the last line of a file that doesn't end with a newline with the first line from the next file, forming one long line. Probably not what you want.