Here's a simple unix2dos.bat file that preserves blank lines and exclamation points:
@echo off
setlocal DisableDelayedExpansion
for /f "tokens=1,* delims=:" %%k in ('findstr /n "^" %1') do echo.%%l
The output goes to standard out, so redirect unix2dos.bat output to a file if so desired.
It avoids the pitfalls of other previously proposed for /f batch loop solutions by:
1) Working with delayed expansion off, to avoid eating up exclamation marks.
2) Using the for /f tokenizer itself to remove the line number from the findstr /n
output lines.
(Using findstr /n is necessary to also get blank lines: They would be dropped if for /f read directly from the input file.)
But, as Jeb pointed out in a comment below, the above solution has one drawback the others don't: It drops colons at the beginning of lines.
So 2020-04-06 update just for fun, here's another 1-liner based on findstr.exe, that seems to work fine without the above drawbacks:
@echo off
setlocal DisableDelayedExpansion
for /f "tokens=* delims=0123456789" %%l in ('findstr /n "^" %1') do echo%%l
The additional tricks are:
3) Use digits 0-9 as delimiters, so that tokens=*
skips the initial line number.
4) Use the colon, inserted by findstr /n
after the line number, as the token separator after the echo command.
I'll leave it to Jeb to explain if there are corner cases where echo:something
might fail :-)
All I can say is that this last version successfully restored line endings on my huge batch library, so exceptions, if any, must be quite rare!