PC Review


Reply
Thread Tools Rate Thread

Findstr and multi-string AND searches

 
 
Michel Gallant
Guest
Posts: n/a
 
      12th Oct 2003
Can findstr.exe be used for a multi-string AND search?
Is that possible given the limited RegExp capability of Findstr?

I want to search multiple files, subdirectory recursive, and
only find files containing BOTH (or more than 2) strings.

The following command finds 2 search words (in the order
given), but only if they are on the same line:
findstr /s /i /m "Word1.*Word2" *.*

Thanks,
- Michel Gallant
Visual Security MVP


 
Reply With Quote
 
 
 
 
Marty List
Guest
Posts: n/a
 
      12th Oct 2003

"Michel Gallant" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Can findstr.exe be used for a multi-string AND search?
> Is that possible given the limited RegExp capability of Findstr?
>
> I want to search multiple files, subdirectory recursive, and
> only find files containing BOTH (or more than 2) strings.
>
> The following command finds 2 search words (in the order
> given), but only if they are on the same line:
> findstr /s /i /m "Word1.*Word2" *.*
>
> Thanks,
> - Michel Gallant
> Visual Security MVP
>
>


This isn't the most efficient solution since it will read each file twice,
but you could use the "&&" conditional processing symbol to execute a second
findstr only if the first one succeeds. Something like this:

@Echo Off
SetLocal
Set SOURCE=C:\Temp
For /R %SOURCE% %%A In (*.*) Do (
findstr /i "Word1" %%A>NUL && findstr /i /m "Word2" %%A
)


 
Reply With Quote
 
 
 
 
Michel Gallant
Guest
Posts: n/a
 
      13th Oct 2003
Thanks Marty. That seems to do the trick (refreshing my bat knowledge)

Is there a way to filter out (to Nul) lines in the resursion that fail like:
FINDSTR: Cannot open C:\Progra .....

Thanks,
- Mitch

"Marty List" <(E-Mail Removed)> wrote in message
news:bmc16k$k1hrk$(E-Mail Removed)-berlin.de...
>
> "Michel Gallant" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Can findstr.exe be used for a multi-string AND search?
> > Is that possible given the limited RegExp capability of Findstr?
> >
> > I want to search multiple files, subdirectory recursive, and
> > only find files containing BOTH (or more than 2) strings.
> >
> > The following command finds 2 search words (in the order
> > given), but only if they are on the same line:
> > findstr /s /i /m "Word1.*Word2" *.*
> >
> > Thanks,
> > - Michel Gallant
> > Visual Security MVP
> >
> >

>
> This isn't the most efficient solution since it will read each file twice,
> but you could use the "&&" conditional processing symbol to execute a second
> findstr only if the first one succeeds. Something like this:
>
> @Echo Off
> SetLocal
> Set SOURCE=C:\Temp
> For /R %SOURCE% %%A In (*.*) Do (
> findstr /i "Word1" %%A>NUL && findstr /i /m "Word2" %%A
> )
>
>



 
Reply With Quote
 
Matthias Tacke
Guest
Posts: n/a
 
      13th Oct 2003
"Michel Gallant" schrieb:

>Thanks Marty. That seems to do the trick (refreshing my bat knowledge)
>
>Is there a way to filter out (to Nul) lines in the resursion that fail like:
>FINDSTR: Cannot open C:\Progra .....
>

Have you tried to redirect the error output with 2>NUL?

More on this you will find with Start/Help/Search for redirection.

hth
Matthias
 
Reply With Quote
 
Michel Gallant
Guest
Posts: n/a
 
      13th Oct 2003
Thanks.
Is there a recommended recent Batch file programming book
which includes extra features available for W2k+ ??
I have somewhere "MS-DOS Batch Files" K., Jamsa 1993

- Mitch

"Matthias Tacke" <(E-Mail Removed)> wrote in message news:bme57p$efj$05$(E-Mail Removed)-online.com...
> "Michel Gallant" schrieb:
>
> >Thanks Marty. That seems to do the trick (refreshing my bat knowledge)
> >
> >Is there a way to filter out (to Nul) lines in the resursion that fail like:
> >FINDSTR: Cannot open C:\Progra .....
> >

> Have you tried to redirect the error output with 2>NUL?
>
> More on this you will find with Start/Help/Search for redirection.
>
> hth
> Matthias



 
Reply With Quote
 
Matthias Tacke
Guest
Posts: n/a
 
      13th Oct 2003
"Michel Gallant" schrieb:

>Thanks.
>Is there a recommended recent Batch file programming book
>which includes extra features available for W2k+ ??
>I have somewhere "MS-DOS Batch Files" K., Jamsa 1993
>
>- Mitch
>

Btw. you can start with help on the commandline and then
help command. Or search the windows help for the topics you are
interested in. The websites are mostly a compilation of these sources.

hth
Matthias

*** I copied the following out of Message in a.m.b.nt.***
Tim Hill, _Windows NT Shell Scripting_

<http://www.seanet.com/~shardy/ntscript.html>
Win NT CMD programming

<http://www.ss64.com/nt>
Simon Sheppard's WinNT Command Reference


--
Phil Robyn
Univ. of California, Berkeley
 
Reply With Quote
 
guard
Guest
Posts: n/a
 
      13th Oct 2003
"Michel Gallant" wrote
> Is there a recommended recent Batch file programming book
> which includes extra features available for W2k+ ??
> I have somewhere "MS-DOS Batch Files" K., Jamsa 1993
>
> - Mitch


The FindStr Page will show you the difference between FindStr for
NT/2K/XP/K3
(http://TheSystemGuard.com/TheGuardBo...xt/FindStr.htm)

For comparisons of all internal Cmd.exe commands, see
(http://TheSystemGuard.com/TheGuardBook/CCS-Int)

*******

-tsg
____________________________________________________________
TheSystemGuard.com | BoomingOrFuming.com | MountCommands.com
Free and "Almost Free" Knowledge for Windows System Admins!


 
Reply With Quote
 
Michel Gallant
Guest
Posts: n/a
 
      13th Oct 2003
Thanks for these references.
- Mitch
http://pages.istar.ca/~neutron

"guard" <^T^S^G^n^e^w^s^@TheSystemGuard.com> wrote in message
news:bmeffl$ler0r$(E-Mail Removed)-berlin.de...
> "Michel Gallant" wrote
> > Is there a recommended recent Batch file programming book
> > which includes extra features available for W2k+ ??
> > I have somewhere "MS-DOS Batch Files" K., Jamsa 1993
> >
> > - Mitch

>
> The FindStr Page will show you the difference between FindStr for
> NT/2K/XP/K3
> (http://TheSystemGuard.com/TheGuardBo...xt/FindStr.htm)
>
> For comparisons of all internal Cmd.exe commands, see
> (http://TheSystemGuard.com/TheGuardBook/CCS-Int)
>
> *******
>
> -tsg
> ____________________________________________________________
> TheSystemGuard.com | BoomingOrFuming.com | MountCommands.com
> Free and "Almost Free" Knowledge for Windows System Admins!
>
>



 
Reply With Quote
 
Michel Gallant
Guest
Posts: n/a
 
      13th Oct 2003
OK, here is what I have for simple case there bat
reads in 2 args as search strings.

@Echo Off
SetLocal
Set SOURCE=C:\Progra~1\.......
For /R %SOURCE% %%A In (*.*) Do (findstr %1 %%A>NUL 2>Nul && findstr /m %2 %%A)

How do I modify this if the Set SOURCE= contains a string with explicit spaces (e.g. Program Files
....)
instead of 8.3 path names?

Thanks,
- Mitch

"Matthias Tacke" <(E-Mail Removed)> wrote in message news:bme57p$efj$05$(E-Mail Removed)-online.com...
> "Michel Gallant" schrieb:
>
> >Thanks Marty. That seems to do the trick (refreshing my bat knowledge)
> >
> >Is there a way to filter out (to Nul) lines in the resursion that fail like:
> >FINDSTR: Cannot open C:\Progra .....
> >

> Have you tried to redirect the error output with 2>NUL?
>
> More on this you will find with Start/Help/Search for redirection.
>
> hth
> Matthias



 
Reply With Quote
 
Matthias Tacke
Guest
Posts: n/a
 
      13th Oct 2003
"Michel Gallant" schrieb:

>OK, here is what I have for simple case there bat
>reads in 2 args as search strings.
>
>@Echo Off
>SetLocal
>Set SOURCE=C:\Progra~1\.......


Set Source="C:\Program Files\...."
Put _either_ Set or the "%SOURCE%" in Parenthes's

>For /R %SOURCE% %%A In (*.*) Do (findstr %1 %%A>NUL 2>Nul && findstr >/m %2 %%A)
>How do I modify this if the Set SOURCE= contains a string with
>explicit spaces (e.g. Program Files ...)
>instead of 8.3 path names?
>

hth
Matthias
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Warning: Control f in Windows 8 no longer searches a specificframes, it now searches all frames long time windows user Windows Vista General Discussion 3 9th Feb 2010 03:41 AM
what is with file search on XP? It seems like it searches all types of files, has no sense about what is searches first, takes FOREVER, on windows 98 a file search took about 1/1000 the time. Fact Attack Windows XP General 2 31st Aug 2006 12:13 AM
Getting valid web searches and avoiding sites that contaminate web searches David McRitchie Microsoft Excel New Users 1 13th Jun 2006 03:00 AM
for, findstr, and dir =?Utf-8?B?SGFs?= Windows XP General 3 16th Jun 2005 10:20 AM
My Computer Searches and Searches John Corson Windows XP Basics 1 3rd Dec 2004 03:29 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:18 PM.