for loop -> Pipe - not working

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 461
Joined: 07 Jan 2016 07:47

for loop -> Pipe - not working

#1 Post by SIMMS7400 » 03 Jun 2020 09:31

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

penpen
Expert
Posts: 1822
Joined: 23 Jun 2013 06:15
Location: Germany

Re: for loop -> Pipe - not working

#2 Post by penpen » 03 Jun 2020 15:02

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

SIMMS7400
Posts: 461
Joined: 07 Jan 2016 07:47

Re: for loop -> Pipe - not working

#3 Post by SIMMS7400 » 04 Jun 2020 04:28

Thank you, PenPen!!! That worked like a charm!! Stupid oversight on my part, I know it was real simple.

Thank you, again!

Post Reply