Page 1 of 1

for loop -> Pipe - not working

Posted: 03 Jun 2020 09:31
by SIMMS7400
Hi Folks -
I"m trying to pipe the results of a text file to a FIND command to return the found string. I have this code but it's returning everything after the second delim, regarding if its the correct string I'm passing in as the search mask.

Any idea?

Code: Select all

FOR %%A IN ( "StartMonth" ) DO (
    FOR /F "tokens=2 delims==" %%a IN (C:\TEMP\variablefile.txt ^| FIND "%%~A") DO (
        echo %%a
    )
)
pause
Variablefile.txt looks like this:

Code: Select all

StartMonth=Apr
Year1=2020

Re: for loop -> Pipe - not working

Posted: 03 Jun 2020 15:02
by penpen
I think you meant to use (untested):

Code: Select all

FOR %%A IN ( "StartMonth" ) DO (
    FOR /F "tokens=2 delims==" %%a IN ('type Z:\TEMP\variablefile.txt ^| FIND "%%~A"') DO (
        echo %%a
    )
)

But you could also use the find-command with a filename (untested):

Code: Select all

FOR %%A IN ( "StartMonth" ) DO (
    FOR /F "tokens=2 delims==" %%a IN ('FIND "%%~A" "Z:\TEMP\variablefile.txt"') DO (
        echo %%a
    )
)
penpen

Re: for loop -> Pipe - not working

Posted: 04 Jun 2020 04:28
by SIMMS7400
Thank you, PenPen!!! That worked like a charm!! Stupid oversight on my part, I know it was real simple.

Thank you, again!