Skip lines inside nested for loop

July 1, 2011 at 17:17:22
Specs: Windows XP
I am trying do the following -

I have to parse multiple files (numbers can vary from 1 to 50+), and in each file, I need to find a segment of lines that start with a specific entry and process all lines below that entry. The number of lines above that varies (anywhere from a 50 to 50000 lines). Here is what I tried -

@echo off

setLocal EnableDelayedExpansion

for /F %%A in (%file_list%) do (
SET file_name=%%A

:: -----Check if file is missing-----
if not exist !file_name! (
SET SuccessFlg=P
goto End
)

:: ----Check for Statistics----
for /F "tokens=1,* delims=:" %%A in ('find /c "Summary" !file_name!') do SET var1=%%B
if !var1! equ 0 goto End

for /F "tokens=1,* delims=[]," %%i in ('find /n "Summary" !file_name!') do SET LineNoSrc=%%i

for /F "skip=%LineNoSrc% tokens=1-13* delims=[],:()> " %%a in (!file_name!) do (
some commands)

goto End
)
:End
@echo on

I tried both %LineNoSrc% as well as !LineNoSrc!. Neither of them seem to work.

How do I fix this?

Thanks


See More: Skip lines inside nested for loop

Report •

#1
July 2, 2011 at 03:24:29
What is the content of %LineNoSrc%?


Please come back & tell us if your problem is resolved.


Report •

#2
July 2, 2011 at 04:12:54
The only way I've been able to dynamically change the skip values was to set a variable that also contained skip=

    for /F "tokens=1,* delims=[]," %%i in ('find /n "Summary" !file_name!') do (
        SET skip=skip=%%i
    )
    for /F "!skip! tokens=1-13* delims=[],:()> " %%a in (!file_name!) do (
        some commands
    )

When your only tool is a hammer, every problem looks like a nail.


Report •

#3
July 5, 2011 at 11:33:48
I tried that. I am getting the following error -

!skip! tokens=1-13* delims=[],:()> " was unexpected at this time.


Report •

Related Solutions

#4
July 5, 2011 at 11:34:38
That gives me the Line number in the file where the Sumary segment starts. I am using that to skip that many lines in the for loop

Report •

#5
July 5, 2011 at 13:18:06
This work

@echo off
SetLocal EnableDelayedExpansion

set FileName=xx.txt
cls
for /F "tokens=1,* delims=[]," %%a in ('find /n "Summary" %FileName%') do (
set LineNo=%%a
)
echo LineNo=%LineNo%
echo.
for /F "skip=%LineNo% tokens=* delims=" %%a in (%FileName%) do (
echo %%a
)


Report •

Ask Question