As dbham said, this can be done for / f as well, but it's a bit more complicated.
80% simple solution
setlocal EnableDelayedExpansion
set "var="
set LF=^
rem *** Two empty lines are required for the linefeed
FOR /F "delims=" %%a in (myFile.txt) do (
set "var=!var!!LF!%%a"
)
echo !var!
But this fails:
- If the line is empty, it will be skipped
- If the line starts with ;, the EOL character - If the line contains !(and carriage)
But then you could use a more complex solution
@echo off
SETLOCAL DisableDelayedExpansion
set "all="
FOR /F "usebackq delims=" %%a in (`"findstr /n ^^ aux1.txt"`) do (
set "line=%%a"
SETLOCAL EnableDelayedExpansion
set "line=!line:#=#S!"
set "line=!line:*:=!"
for /F "delims=" %%p in ("!all!#L!line!") do (
ENDLOCAL
set "all=%%p"
)
)
SETLOCAL EnableDelayedExpansion
if defined all (
set "all=!all:~2!"
set ^"all=!all:#L=^
!"
set "all=!all:#S=#!"
)
echo !all!
?
-, findstr /n ^^ ,
1:My first Line
2:; beginning with a semicolon
3:
4:there was an empty line
, EOL ;.
, , , ! ^.
, (, delim : ).
# #S, , .
?
, , FOR/F ,
linefeed ( #L), #L, # #S, .
/ endlocal, all line.
FOR/F-endlocal, %%p endlocal.
, , , all, .
#L , .
#S #.
, ...