find in txt files based on list.txt

May 25, 2010 at 01:08:14
Specs: Windows XP, 3.199 GHz / 1526 MB
Hello.

This task seems simple, but I can't deal with it.

The idea:

- I have LIST.TXT with such content:

120101_1.0007.4861/2
120101_1.0007.4862
120101_1.0007.4863
120101_1.0007.4864
120101_1.0007.4865
120101_1.0007.4866
120101_1.0007.4867
120101_1.0007.4868/2
120101_1.0007.4868/3

- On the basis of this list.txt I want to search other TXT files (which are in different subdirectories). They have this content:

120101_1.0007.4863 20.4352016947 49.9919019834
120101_1.0007.4870 20.4351787334 49.9917309482
120101_1.0007.4867 20.4351431712 49.9915522091
120101_1.0007.4872 20.4351336613 49.9912329739

- As a result, I want to get the output file RESULT.TXT which should include searched rows of TXT files:

120101_1.0007.4863 20.4352016947 49.9919019834
120101_1.0007.4867 20.4351431712 49.9915522091


I try to use this loop, but does not return a result:

for /f "delims=" %%i in (LIST.TXT) do (
find "%i%" folder/*/*.txt >> RESULT.TXT
)

Any ideas?


See More: find in txt files based on list.txt

Report •

#1
May 25, 2010 at 08:38:53
@echo off & setlocal
for /f "tokens=1 delims=/" %%a in (list.txt) do >> noslash.txt echo %%a
for /f "tokens=2 delims=:" %%a in ('findstr /b /g:noslash.txt /s *.txt') do >> result.txt echo %%a
::-------- end
the only reason you need the second for-loop is to remove
the filenames from the beginning of the lines.
the first loop removes the /x items from list.txt. Not sure if you needed that, if not,
eliminate the loop and just use list.txt directly in the second loop.

Report •
Related Solutions


Ask Question