I tried not to post a question about it. And find it myself. I failed.
I know the LineFeed. I'm just not that bright

set forEmacro=^^^^^^^"eol^^^^=^^^^^^^%LF%%LF%^%LF%%LF%^^^%LF%%LF%^%LF%%LF%^^^^ delims^^^^=^^^^^^^"
What's the purpose of this ?
Moderator: DosItHelp
Code: Select all
FOR /F "eol=<LF> delimns=" ...
EdDyreen wrote:What's the purpose of this ?
Code: Select all
@echo off
setlocal
set lf=^
:: Here is a macro with a FOR /F that is guaranteed to preserve the entire line
:: because both eol and delims are effectively disabled. It works, but it is
:: ugly, hard to code and hard to read
::
set simpleMacro1=for /f ^^^"eol^^=^^^%lf%%lf%^%lf%%lf%^^ delims^^=^^^" %%a in (";Please preserve this line") do echo %%a
echo Results of simpleMacro1:
%simpleMacro1%
:: I want to build a simple macro that makes the coding easier
set macro_ForEntireLine=^^^^^^^"eol^^^^=^^^^^^^%lf%%lf%^%lf%%lf%^^^%lf%%lf%^%lf%%lf%^^^^ delims^^^^=^^^^^^^"
:: Now I can build my macro much easier. It reads well and gives the same results
set simpleMacro2=for /f %macro_ForEntireLine% %%a in (";Please preserve this line") do echo %%a
echo:
echo Results of simpleMacro2:
%simpleMacro2%
echo:
echo As was the goal, both macros end up with identical definitions:
set simpleMacro
Code: Select all
Results of simpleMacro1:
;Please preserve this line
Results of simpleMacro2:
;Please preserve this line
As was the goal, both macros end up with identical definitions:
simpleMacro1=for /f ^"eol^=^
^ delims^=^" %a in (";Please preserve this line") do echo %a
simpleMacro2=for /f ^"eol^=^
^ delims^=^" %a in (";Please preserve this line") do echo %a
Thanks to dbenham,
I didn't know that you can disable the eol-character, if it is one of the delims-characters.
But I suppose I found a way to disable the eol even if the delims is empty.
Code:
setLocal EnableDelayedExpansion
set lf=^
for /F ^"eol^=^
delims^="" %%a in ("^^caret!lf!;semicolon!lf! space!lf!""quote") do echo '%%a'
It is obvious that the eol should be a <LF>, but as the FOR /F splits at each <LF>, it is the same as eol would be empty.
jeb
Code: Select all
@echo off &setLocal EnableDelayedExpansion
for /F "delims=""" %%a in ("caret " " quote") do echo 'a=%%a' 'b=%%b'
for /F "delims="^" %%a in ("caret " " quote") do echo 'a=%%a' 'b=%%b'
pause
exit /b
Code: Select all
@echo off
setlocal disableDelayedExpansion
set "str=skip 1st line,^caret,;semicolon, space,"quote,!exclamation"
setLocal EnableDelayedExpansion
set ^"str=!str:,=^
!"
echo str=!str!
echo:----------------
for /F ^"usebackq^ skip^=1^ eol^=^
delims^=^" %%a in ('!str!') do (
setlocal disableDelayedExpansion
echo '%%a'
endlocal
)
echo:---------------
setlocal disableDelayedExpansion
for /f ^"eol^=^
delims^=^" %%a in (";eol disabled so line preserved") do echo %%a
Code: Select all
set ^"str=!str:,=^
!"
It is useful for building macros. It makes it convenient to build a macro with a FOR /F that is guaranteed to read the entire line (no eol, no delims).
It works just fine, no prep requiredEdDyreen wrote:I just need to know one other thing, is it really bulletproof, have you tested this thoroughly with strings like:
" hjfjkfdfhj333""'" " " | | && || >> << ^^" " " " "8765 àç!è( "
I bet the quotes have to be even or it will still fail
So we still have to pre-prepare the input.
Code: Select all
;Please don't ignore me!
This is all good!
Follow the !path! of enlightenment.
" hjfjkfdfhj333""'" " " | | && || >> << ^^" " " " "8765 àç!è( "
"&"&"^"^">">"<"<"|"|"("(")")"
Code: Select all
@echo off
setlocal
if not defined macro\load.macro_RtnLib call macro_RtnLib
set n=0
set macro1=for /f %macro_ForEntireLine% %%s in (test.txt) do (%\n%
set /a "n+=1"%\n%
set "ln=%%s"%\n%
setlocal EnableDelayedExpansion%\n%
echo line!n!=!ln!%\n%
endlocal%\n%
)
%macro1%
Code: Select all
line1=;Please don't ignore me!
line2= This is all good!
line3=Follow the !path! of enlightenment.
line4=" hjfjkfdfhj333""'" " " | | && || >> << ^^" " " " "8765 àç!è( "
line5="&"&"^"^">">"<"<"|"|"("(")")"
DOSKEY supports approximately 61900 bytes. Due to an error in the DOSKEY program that causes DOSKEY to mark memory as unused when it terminates and stays resident, specifying a buffer size larger than this amount causes the computer to hang.