1

I have the following code:

set "string_pdf=<module>PDF-hul</module>"
set string1=Well-Formed and valid
set /a loop100=0

for /f "tokens=*" %%i in ('dir /a-d /b /s %output%') do (
    for /f "tokens=3 delims=>/<" %%p in ('find  "%string_pdf%" "%%i" && find "%string1%" "%%i" ') do (
        echo %%~ni >> %output%\pdf_hul.txt
        set /a loop100+=1
    )
)

I'm going through all XML's that are located in the %output% folder and trying to find the co-occurrence of Well-Formed and valid and <module>PDF-hul</module> in one xml file. This code works when I'm searching only with one find command for one variable. But when I add the second one I get a syntactical error.

How to find both variables string_pdf and string1 in one xml (aren't in one line)?

1
  • You have to escape the && --> ^&^& Commented Nov 1, 2018 at 13:52

1 Answer 1

2

You would have to escape the && --> ^&^& but
IMO the 2nd for isn't neccessary simply use a findstr with two strings and
a conditional execution on success && and suppress any output of the findstr

:: Q:\Test\2018\11\01\SO_53102597.cmd
@Echo off
set output=X:\Path
set "string_pdf=<module>PDF-hul</module>"
set string1=Well-Formed and valid
set /a loop100=0

for /f "tokens=*" %%i in ('dir /a-d /b /s "%output%*.xml"') do (
    findstr /IM /c:"%string_pdf%" "%%i" >NUL 2>&1 && (
        findstr /IM /c:"%string1%" "%%i" >NUL 2>&1 && (
            echo %%~ni >> %output%\pdf_hul.txt
            set /a loop100+=1
        )
    )
)
set loop
Sign up to request clarification or add additional context in comments.

9 Comments

That works for one counter loop100. But if I want to count additionally the coccurrence of e.g. string_pdf and string2 I use the counter loop200 and copy ( findstr /c:"%string_pdf%" /c:"%string2%" "%%i" >NUL 2>&1 && ( echo %%~ni >> %output%\pdf_hul.txt set /a loop200+=1 ) In this case the counters don't work correct.
ATM the co-occurence is counted, to count them individually you'd need separate findstr only incrementing the one occurence.
I don't understand how do you mean to separate them?
As I understand I can't count co-occurrences individually using only one counter
You are right, I revised the code, please check it out. One error was no extension on the dir, and the findstr has to be nested otherwise it's an or not a and codition.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.