findstr question


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.
 
Ad

Advertisements

M

Matthias Tacke

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
 
Ad

Advertisements

D

djc

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top