fooling around a bit with batch files, and wondering why there is a huge difference in time required to output a file in below scenarios :
Scenario 1 : Simple traverse through a log file,and for every row always taking the 5th token, unless it contains a filter string.
(for /f "tokens=5" %%a in (test.log) do @echo(%%a) | findstr /v "filter_1 filter_2" > !filter!.txt
This works great, going through a 50M file returns me a smaller 10Mb file in 10 seconds.
Scenario 2 : Do exactly the same, but add something in front and end of the token so I can output as an xml file rather than a text file. To do so I had to rebuild it a bit as below
echo ^<rows^> > test.xml
>>test.xml (
for /f "tokens=5" %%a in (
'findstr /v "filter1 filter2" test.log'
) do echo ^<r a="%%a"/^>
)
echo ^</rows^> >> test.xml
It works as expected for small files,but takes like forever for large files. Is there anyway to achieve what I want with scenario 2 but using the scenario 1 syntax, as that seems much more efficient.