Below script is working fine for a single file :
Code: Select all
setlocal EnableDelayedExpansion
rem Assemble the list of line numbers
set numbers=
for /F "delims=:" %%a in ('findstr /I /N /C:"PASS" 1.xml') do (
set /A before=%%a-10, after=%%a+2
set "numbers=!numbers!!before!: !after!: "
)
(for /F "tokens=1* delims=:" %%a in ('findstr /N "^" 1.xml ^| findstr /B "%numbers%"') do echo %%b) >> Out.txt
Out.txt for above script rightly displays the specific lines from 1.xml file But it doesn't work when I try to use FOR loop to pass all XML files(1.xml, 2.xml, 3.xml etc) read one by one from a text file.
Code: Select all
@echo off
setlocal EnableDelayedExpansion
FOR /F %%x in (input.txt) DO (
set numbers=
for /F "delims=:" %%a in ('findstr /I /N /C:"PASS" %%x') do (
set /A before=%%a-10, after=%%a+2
set "numbers=!numbers!!before!: !after!: "
)
(for /F "tokens=1* delims=:" %%a in ('findstr /N "^" %%x ^| findstr /B "%numbers%"') do echo %%b) > Out.txt
)
The output on running above script is: FINDSTR: No search strings
A sample Input.txt would look something like this:
1.xml
2.xml
3.xml Here is a sample XML file which could be used as input for both the scripts: https://www.dropbox.com/s/h16fzdurvogrp9l/1.xml?dl=0 Please download & rename sample xml as 1.xml, 2.xml etc
All the XML files and batch script are located in same directory. In the last FOR Loop I have also tried using findstr /B "!numbers!", still the result was same.
Any suggestions whats going wrong here?
Thanks
San