troubleshooting Question

command line Batch for /f lookup, into for /r loop

Avatar of urfried
urfriedFlag for Netherlands asked on
Microsoft DOS
9 Comments1 Solution825 ViewsLast Modified:
Hello gents,

Now i am getting the hang of creating very handy batch files,
i am trying to gain the complexity of my batches into a next level, but i have a problem immediately :).

I'll try to explain simple:

I have multiple files in a single dir.
With a FOR /R "%CD%" %%F IN (*.txt) DO (.......loop, i know which files and want to build a log file.
I echo some text with name of the 1st file found in the loop. So far it works.

Than the problem:
I would like to like to search for text-string in the files found in the loop above, and output the text-string into the log file:

for /f "tokens=* delims= " %%A in ( 'FIND /i "usr_device" ^< "%cd%\%%~nF.txt"' )  do set usr_output0=%%A
     echo %usr_output0% >> %log%

The single commandline is correct (tested), but it's not working within the loop.

Anyone having an idea ?
Is the question clear enough ?

I want a logfile like this:
 
09390.txt
------------------------------------------
usr_device                        NL03PR178
==========================================
      
09628.txt
------------------------------------------
usr_device                        NL03PR176
==========================================      




 09628.txt 09390.txt
set log="%cd%\test.txt"
echo. > %log%

:############################################################################################

FOR /R "%CD%" %%F IN (*.txt) DO (
 echo %%~nF.txt >> "%cd%\test.txt"
 echo ------------------------------------------>> %log%
   ( for /f "tokens=* delims= " %%A in ( 'FIND /i "usr_device" ^< "%cd%\%%~nF.txt"' )  do set usr_output0=%%A
     echo %usr_output0% >> %log%
   )
 echo ==========================================>> %log%	
)

pause
batch.jpg
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros