findstr question

  • Thread starter Thread starter djc
  • Start date Start date
D

djc

is there a way to specify an 'and' condition for findstr.. for example I
would like to only show lines from a file or command output that have
"ThisWord" AND "ThatWord". Can I do this with findstr alone? or maybe by
chaining a few commands together? maybe a different command?

any input is greatly appreciated. Thanks.
 
djc said:
is there a way to specify an 'and' condition for findstr.. for example I
would like to only show lines from a file or command output that have
"ThisWord" AND "ThatWord". Can I do this with findstr alone? or maybe by
chaining a few commands together? maybe a different command?

any input is greatly appreciated. Thanks.
By default findstr uses regexp mode.
If you have a certain order of your strings put a ".*" between them.
Findstr has a flaw with spaces in the search strings. Yo may replace
them with a dot (in regexp a dot is any char, an asterisk any number
of the previous)

findstr /I "ThisWord.*ThatWord" yourfile.txt

will output only lines with both strings in that order.

If your strings contain some special chars they may have to escaped
with a ^

The issue with the space does not occur when getting the search
strings from a file with the /G: option.

HTH
 
great! thank you.

Matthias Tacke said:
By default findstr uses regexp mode.
If you have a certain order of your strings put a ".*" between them.
Findstr has a flaw with spaces in the search strings. Yo may replace
them with a dot (in regexp a dot is any char, an asterisk any number
of the previous)

findstr /I "ThisWord.*ThatWord" yourfile.txt

will output only lines with both strings in that order.

If your strings contain some special chars they may have to escaped
with a ^

The issue with the space does not occur when getting the search
strings from a file with the /G: option.

HTH
 
Back
Top