echo text with end of line unix from a Windows batch script (.bat)

advertisements

Say I have the following batch script:

For ... DO (
SET VAL=%%B
IF defined VAL echo %%A=%%B >> %OUTPUT_FILEPATH%
)

How could I get the echo to output using unix (just line feed) line endings?

Alternatively, could I write the file as-is then convert it from the batch script afterwards? (some kind of find /r/n and replace with /n? if so, how would I do that?)

edit: I'd like a self-contained solution (i.e. one that doesn't involve downloading extra utilities, and can be done from within the batch script itself [windows 7])


taken from Macros with parameters appended

formatting is tricky, but try

set ^"LF=^

^" don't remove previous line & rem line feed (newline)
set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"& rem define newline with line continuation

For ... DO (
SET VAL=%%B
IF defined VAL <nul set/P^=%%A=%%B%\n%>> %OUTPUT_FILEPATH%
)

or, to avoid the leading space after first line

<nul set/P^=%%A=%%B%\n%^>> %OUTPUT_FILEPATH%