Computing.Net > Forums > Programming > Batch to search in multiple files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch to search in multiple files

Reply to Message Icon

Name: svkrec
Date: September 4, 2008 at 12:47:44 Pacific
OS: Win XP
CPU/Ram: P4/1GB
Product: Dell
Comment:

Hi, I need help to write one MS-DOS batch file. I have one file 'FNin.txt' which contains following values
srchstr1
srchstr2
srchstr3
...
srchstr999

I need to read each string from 'FNin.txt' and then search this string in all the text files present in sub-folders and write the file names that contain search string in another output file, say 'FNout.txt' in following format
srchstr1 - file1.txt, file3.txt, file21.txt
srchstr2 - file4.txt, file8.txt, file348.txt etc

I have to repeat above for all the strings present in 'FNin.txt'. I know FINDSTR can be used, but I want to know how can I write a batch file for it.

Thanks in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: svkrec
Date: September 8, 2008 at 22:28:53 Pacific
Reply:

Found Solution (output now a bit changed) -

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
For /F "tokens=1" %%A in (FNin.txt) Do (
echo %%A, ###### >> FNout.txt
For /F "delims=" %%B in ('FINDSTR /M /S /I %%A *.txt') DO (
echo %%A, %%B >> FNout.txt
)
)


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch to search in multiple files

Searching in .pdf files www.computing.net/answers/programming/searching-in-pdf-files/9255.html

Batch to search and copy to new Dir www.computing.net/answers/programming/batch-to-search-and-copy-to-new-dir/16809.html

Dos script to search into .txt file www.computing.net/answers/programming/dos-script-to-search-into-txt-file/16695.html