Page 1 of 1

search list of strings in a file

Posted: 05 Mar 2013 02:22
by ladduq
Hi


I have a file which contains a list of keywords up to 300.
These keywords are to be searched one by one in another
text file which has the matching keyword lines and output
the matching lines in another file.

I have made it upto this but unable to get output.pls suggest

@echo off
cls
set info=The_file_in_which_keywords_are_tobe_searched_and_output_in_resultsfile.txt
set results=results.txt
FOR /F "tokens=*" %%1 IN ('findstr /G:search_list_file_which_contains_keywords_or_search_strings.txt %info%') DO echo %%1 >>%results%

Thanks

Re: search list of strings in a file

Posted: 05 Mar 2013 03:06
by mfm4aa
Your code is working for me. What kind of issue do you have?

Re: search list of strings in a file

Posted: 05 Mar 2013 04:28
by foxidrive
ladduq wrote:FOR /F "tokens=*" %%1 IN ('findstr /G:search_list_file_which_contains_keywords_or_search_strings.txt %info%') DO echo %%1 >>%results%



Avoid using numerals. Use alpha characters.

Re: search list of strings in a file

Posted: 05 Mar 2013 07:35
by ladduq
mfm4aa wrote:Your code is working for me. What kind of issue do you have?



yes i also tested the code but only for about 10 keywords i tested and it was working fine.

However when i implemented the same for 300 keywords it is not working.It is not displaying the output in results file.But when i manually find in the file there were instances matching the keywords.

Re: search list of strings in a file

Posted: 05 Mar 2013 07:52
by foxidrive
Show us a scenario where it fails. Try the keywords and file data and see if it fails. Post them here.

Re: search list of strings in a file

Posted: 05 Mar 2013 08:20
by mfm4aa
There are some FINDSTR issues, e.g.
Recommendation - Always explicitly specify /L literal option or /R regular expression option when using "string argument" or /G:file.

http://stackoverflow.com/questions/8844 ... 73#8844873

Re: search list of strings in a file

Posted: 05 Mar 2013 08:24
by foxidrive
Case sensitive searches is also a trap at times. The /I switch is often necessary.

Re: search list of strings in a file

Posted: 05 Mar 2013 09:31
by foxidrive
mfm4aa wrote:There are some FINDSTR issues, e.g.
Recommendation - Always explicitly specify /L literal option or /R regular expression option when using "string argument" or /G:file.

http://stackoverflow.com/questions/8844 ... 73#8844873



I found that in another thread using exclusions, and it seems that even if I specify /r the line isn't treated as a regexp if it starts with plain text.

As a test I had this in the exclusions.txt and it excluded out-000001.txt where it should only exclude outtttt and any number of t characters, if it was treated as a regexp. It was treated as a normal msdos wildcard.

out*