in reply to Can anyone figure how this works?

It opens up an input file (first command line argument) and an output file (second command line argument) for writing. Next, it loops through the lines of the input file. The pattern match just verifies that the line is only a newline character. If so, it doesn't print it to the output file, it prints the standard DOSish \r\n combination. Otherwise, it prints the line verbatim.

Yeah, the explanation's longer than the code.

Update: Let's further compact tachyon's replacement into a one-liner: perl -pi.bak -e "s/^\n$/\r\n/" <filename>

©