skip= in FOR /F fails

Oct 20, 2017
31
0
Netherlands
In the textfile "testskip.txt", I have to find the linenumber of the first line with "Platform ID:\t1", from that specific line the first linenumber with "Name ID:\t\t6" and from that specific line the first linenumber with "Offset:\t\t3". I wrote these lines of code:
Code:
@ECHO OFF

for /f %%i in ('ffind /F /L /K /M /E"Platform ID:\t1" TEST2.TXT') do @set PlatformID1LineNumber=%@STRIP[[],%%i]
echo (_1) PlatformID1LineNumber.: %PlatformID1LineNumber

for /f "skip=%%PlatformID1LineNumber%" %%i in ('ffind /F /L /K /M /E"Name ID:\t\t6" TEST2.TXT') do @set NameID6LineNumber=%@STRIP[[],%%i]
echo (_2) NameID6LineNumber.....: %NameID6LineNumber

for /f "skip=%%NameID6LineNumber%" %%i in ('ffind /F /L /K /M /E"Offset:\t\t3" TEST2.TXT') do @set OffsetLineNumber=%@STRIP[[],%%i]
echo (_3) OffsetLineNumber......: %OffsetLineNumber

The first FOR /F works great, but the second and third FOR /F not.
Even if I add the real linenumbers in "skip=", the code doesn't work.
I spend hours looking on the internet for solutions, I tried all kind of suggestions, but nothing works. I can't find the solution.
 

Attachments

  • testskip.btm
    569 bytes · Views: 102
  • testskip.txt
    877 bytes · Views: 111
May 20, 2008
11,547
107
Syracuse, NY, USA
I don't think it likes the "%%" in front of the variable name in the skip option. That variable should be expanded immediately.
Code:
v:\> type doggy.txt
My
dog
has
fleas.

v:\> set skipper=2

v:\> for /f "skip=%%skipper%" %%l in ('ffind /l /k /m /v /e".*" doggy.txt') do echo %l
[1]
[2]
[3]
[4]

v:\> for /f "skip=%skipper%" %%l in ('ffind /l /k /m /v /e".*" doggy.txt') do echo %l
[3]
[4]
 
Last edited:
May 20, 2008
11,547
107
Syracuse, NY, USA
This is a very different approach but it works well with your testskip.txt.
Code:
setlocal
do line in @testskip.txt

    if "%line" == "" iterate
    
    iff %@regex["Platform ID:\t1",%line] == 1 then
        set line1=%_do_loop
        unset /q line2
        unset /q line3
    elseiff %@regex["Name ID:\t\t6",%line] == 1 then
        set line2=%_do_loop
        unset /q line3
    else iff %@regex["Offset:\t\t3",%line] == 1 then
        set line3=%_do_loop
    endiff
    
    iff defined line1 .and. defined line2 .and. defined line3 then
        echo The lines are: %line1 %line2 %line3
        quit
    endiff
    
enddo

echo Not found!

Code:
v:\> testskip.btm
The lines are: 48 51 53
 
Oct 20, 2017
31
0
Netherlands
Hi Vince,

Thanks for helping my out, because I can't my head around it.

When I get "Platform ID:\t1" right (40), "Name ID:\t\t6" (51) and "Offset:\t\t3" (53) will not work.
When I get "Platform ID:\t1" wrong (48), "Name ID:\t\t6" (51) and "Offset:\t\t3" (53) will work.
Like your code.

The right answer is: 40, 51, 53, not: 48, 51, 53.

Cracking my head continues ...

Marcel - Win7Ulti/x64/SP1
 
Oct 20, 2017
31
0
Netherlands
Hi Vince,

If you remove from the line: ffind /l /k /m /v /e".*" option "/v" (showing every marching line on a text search), the result is not 48 but 40.

But now the 2nd and 3rd line. Keep on cracking my head.

Marcel - Win7Ulti/x64/SP1
 
May 20, 2008
11,547
107
Syracuse, NY, USA
Hi Vince,

Thanks for helping my out, because I can't my head around it.

When I get "Platform ID:\t1" right (40), "Name ID:\t\t6" (51) and "Offset:\t\t3" (53) will not work.
When I get "Platform ID:\t1" wrong (48), "Name ID:\t\t6" (51) and "Offset:\t\t3" (53) will work.
Like your code.

The right answer is: 40, 51, 53, not: 48, 51, 53.

Cracking my head continues ...

Marcel - Win7Ulti/x64/SP1
Why do you want 40 instead of 48? I figured you wanted all three line numbers to come from the same "section", namely this one, the last one:
Code:
      0. Platform ID:    1
         Specific ID:    0
         Language ID:    0
         Name ID:        6
         Length:        0
         Offset:        3
 
Oct 20, 2017
31
0
Netherlands
Hi Vince,

The textfile is a sample of the output of TTFDUMP.EXE, which dumps TrueTypeFont information in a textfile.
The structure is explained in Font Names Table.

My goal is to find the "section" with the 3 lines, but I don't know how I can find this section in one search.
So, first I have to find the first section with "Platform ID: 1", several section later I find the section with "Platform ID: 1" and "Name ID: 6" and so on.

Your very different approach was my first working code, but very slow. The dumps can be very long > 400 lines, with takes time to search. My second approach is to feed FFIND lines to search by the FOR /F loop and to use the skip= option so earlier sections are not searched anymore. Otherwise searching for "Name ID: 6" finds a section that starts with "Platform ID: 0".

I suspect that the options of FFIND have influence. I'll look at FIND.EXE and FINDSTR.exe and keep on cracking this problem.

Marcel - Win7Ulti/x64/SP1
 
May 20, 2008
11,547
107
Syracuse, NY, USA
So 48 51 53 is what you want, right? My approach finds it in one pass through the file. I think that will be very hard to do with FOR and FFIND (or FIND.EXE or FINDSTR.EXE) unless you LEAVEFOR when appropriate and wrap the "FOR ... FOR ... FOR" approach in another loop. If you can get that to work, I suspect it'll be quite slow.

Do you have a Gnu GREP.EXE? With it I can do this quite quickly.

Code:
v:\> g:\gnu\grep.exe -n -P  "Platform.*1\n.*\n.*\n.*Name.*6\n.*\n.*Offset.*3" testskip.txt
48:       0. Platform ID:       1
             Specific ID:       0
             Language ID:       0
             Name ID:           6
             Length:            0
             Offset:            3
 
May 20, 2008
11,547
107
Syracuse, NY, USA
And with FFIND:

Code:
v:\> ffind /k /m /l /v /e"Platform.*1\r\n.*\r\n.*\r\n.*Name.*6\r\n.*\r\n.*Offset.*3" testskip.txt
[48]      0. Platform ID:       1

Or, if you want to get really fancy:

Code:
v:\> echo %@strip[[],%@word[0,%@execstr[ffind /k /m /l /v /e"Platform.*1\r\n.*\r\n.*\r\n.*Name.*6\r\n.*\r\n.*Offset.*3" testskip.txt]]]
48
 
Similar threads
Thread starter Title Forum Replies Date
old coot Debugging .btm with >3 arguments fails on step. Support 3
bwawsc2 Check for updates fails to complete Support 9
samintz COPY fails to copy from \\wsl$ Support 20
M Goto fails when a text endtext block precedes the code Support 5
vefatica SETP usually fails with a 32 bit process Support 4
S INPUT fails if the entered text contains pair of square brackets Support 6
B Request Manual Key fails Support 3
L TCC V22 installer fails signature validation Support 0
A Fixed v25 regression: Parameter expansion fails in piped commands Support 2
vefatica START /PGM "name with spaces.URL" fails Support 2
I zip /M fails to delete file after adding to zip file Support 2
Joe Caverly Using a Directory Alias with @iniwrite fails Support 14
A WAD Output redirection to IF block fails with "unbalanced brackets" Support 7
E My echo full file name to the clipboard fails now. Support 2
A Fixed (CMD compat) START /D fails to recognize the switch option. Support 3
B MKLINK requires admin - fails silently. Support 1
D Fixed Take Command 21.0.29 fails – MSVCP140.dll missed Support 6
F Powershell call fails with "Scripting Integrator 2016 (PowerShell)" license error Support 9
fishman@panix.com Version 21.23 fails to install Support 4
D unzip fails to find valid license Support 3
StarliteLemming Fileread fails on Unicode file Support 10
D Upgrade from 19 to 19.10 fails Support 2
C Upgrade to v19.10.42 fails Support 5
D V19 fails to install on Win7-64bit, installer says: Support 2
bervin Webform fails on HTTPS Support 1
thedave Windows 10: Pinned taskbar fails Support 20
P MS VS2013 vsdevcmd.bat fails to run with tcmd 17 x64 Support 10
vefatica @REGQUERY with hostname fails Support 12
tmaynard Bug Typesafe Activator fails under Take Command shell Support 2
R Fixed Internal ZIP command fails to process multiple files Support 3
P Copying descript.ion file fails Support 8
S WAD FTP copy fails in 16.00.25 Support 24
S WAD KEYSTACK fails in TCC-64 Support 2
vefatica Files disappear in Explorer when DEL fails Support 6
T tcc /c "[...]" fails when run from third party terminal Support 11
C Latest TCMDx64 fails on XP Pro x64 Support 1
dcantor WAD dir "ftp:// ..." fails in TCC 15 Support 7
M WAD Copy command fails rather weirdly... Support 2
S WAD COPY from FTP site fails in 14.03.51 Support 9
M Updating environment variable from C++ fails erratically in version 14... Support 57
dcantor Take Command 14 release fails Support 6
S WAD "Mark Forums Read" fails Support 4
dcantor Fixed Take Command 14.0.20 fails Support 19
D Upgrade from b12 fails Support 5
scottb Toolbar filter by directory attribute /A:D fails Support 1
Stefano Piccardi IDE.exe start toobar button fails when % in script path Support 0
H Install fails and removes tcmd Support 4
vefatica 12.10 registration fails Support 3
S PDIR fails in 12.10.55 Support 3
J 4console vbeep fails Support 0

Similar threads