ForEntireLine
Moderator: DosItHelp
ForEntireLine
Can someone link me to where I can study this technique ?
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 ?
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 ?
Re: ForEntireLine
It's simply the way to set the EOL-character to <linefeed> so it is effectivly disabled.
It looks a bit complicated, as Dave decide to write it without helper variables.
In the end it is expanded to
Read more about this, at Re: Sorting tokens within a string
jeb
It looks a bit complicated, as Dave decide to write it without helper variables.
In the end it is expanded to
Code: Select all
FOR /F "eol=<LF> delimns=" ...
Read more about this, at Re: Sorting tokens within a string
jeb
Re: ForEntireLine
EdDyreen wrote:What's the purpose of this ?
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).
Here is a little demo
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
demo results:
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
Dave
Last edited by dbenham on 29 Jul 2011 12:49, edited 1 time in total.
Re: ForEntireLine
Wow jeb, I'm beginning to understand it
But you couldn't have found this by simply guessing, this requires insight !!!
I've been sitting in front of DOS for over 15years & I never figured it out !
Still there's one thing I don't understand, why doesn't this simple test splits to a & b ?
It seems delims refuses to accept " as a valid delimiter ?!
Wow dBenham, what a clever variation
The fact that it's even possible
Ok dBenham now let's study your above post..... hmmm ... hmm ...
dBenham, you know how long I've been looking for someting like this, I bet you were too
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.
I am going to experiment with this...
" hjfjkfdfhj333""'" " " | | && || >> << ^^" " " " "8765 àç!è( "
Whaa that didn't work, I'm always way to optemistic. Only a fool like me would try this.
@dBenham Euh, I guess you are already trained at this, do you know of a variation for EnabledDelayedExpansion
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
But you couldn't have found this by simply guessing, this requires insight !!!
I've been sitting in front of DOS for over 15years & I never figured it out !
Still there's one thing I don't understand, why doesn't this simple test splits to a & b ?
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
It seems delims refuses to accept " as a valid delimiter ?!
Wow dBenham, what a clever variation
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
The fact that it's even possible
Code: Select all
set ^"str=!str:,=^
!"
Ok dBenham now let's study your above post..... hmmm ... hmm ...
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).
dBenham, you know how long I've been looking for someting like this, I bet you were too
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.
I am going to experiment with this...
" hjfjkfdfhj333""'" " " | | && || >> << ^^" " " " "8765 àç!è( "
Whaa that didn't work, I'm always way to optemistic. Only a fool like me would try this.
@dBenham Euh, I guess you are already trained at this, do you know of a variation for EnabledDelayedExpansion
Re: ForEntireLine
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.
test.txt
Code: Select all
;Please don't ignore me!
This is all good!
Follow the !path! of enlightenment.
" hjfjkfdfhj333""'" " " | | && || >> << ^^" " " " "8765 àç!è( "
"&"&"^"^">">"<"<"|"|"("(")")"
test.bat (macro_RtnLib.bat is in my return ANY string safely and easily post)
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%
results:
Code: Select all
line1=;Please don't ignore me!
line2= This is all good!
line3=Follow the !path! of enlightenment.
line4=" hjfjkfdfhj333""'" " " | | && || >> << ^^" " " " "8765 àç!è( "
line5="&"&"^"^">">"<"<"|"|"("(")")"
Dave
-
- Posts: 287
- Joined: 16 Mar 2011 19:17
- Location: scriptingpros.com
- Contact:
Re: ForEntireLine
Ok, with all due respect and as polite as I can be.
My dos is not nearly this advanced nor do I know if I would ever want it to be.
I understand what is happening here, but what is the purpose?
I get one thing that the macros help to speed things up, but is that it?
What are these good for?
Thank You.
My other question why can't we just use doskey for this...
Or why don't you just write something that fixes this.
My dos is not nearly this advanced nor do I know if I would ever want it to be.
I understand what is happening here, but what is the purpose?
I get one thing that the macros help to speed things up, but is that it?
What are these good for?
Thank You.
My other question why can't we just use doskey for this...
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.
Or why don't you just write something that fixes this.
Re: ForEntireLine
We are simply trying to evaluate a line of text without for corrupting our line
This has nothing to do with Doskey.
macros help to speed things up thats all they are good for yes but still:
$MacroSpeed = $FunctionSpeed \ $Divider
$Divider get's larger if filesize get's larger !
[SOLVED] SET /a -- Random Number?
http://www.dostips.com/forum/viewtopic.php?f=3&t=1817
This has nothing to do with Doskey.
macros help to speed things up thats all they are good for yes but still:
$MacroSpeed = $FunctionSpeed \ $Divider
$Divider get's larger if filesize get's larger !
[SOLVED] SET /a -- Random Number?
http://www.dostips.com/forum/viewtopic.php?f=3&t=1817