Tom
Tom

Reputation: 6707

using FIND command to find two string from one line with cmd.exe

How to detect the following string from file safely with FIND (cmd.exe default commands), while the name minnie can be anything? its just that FROM: line has [email protected] on it.

From: "Minnie" <[email protected]>

it should not be mixed to this TO line :

To: <[email protected]>

e.g. this batch file row does not work properly :

find "[email protected]" abc.txt

Upvotes: 1

Views: 19156

Answers (3)

Joey
Joey

Reputation: 354516

You can use findstr instead of find which has more advanced capabilities, like regular expression matching.

findstr /r /c:"^From:.*<[email protected]>" test.txt

will find the specified e-mail address only when the line starts with "From:".

findstr is also included by default at least since Windows 2000.

Upvotes: 4

Helen
Helen

Reputation: 97677

Try two pipelined find commands, like this:

find "[email protected]" abc.txt | find "From:"

The former searches for all lines containing "[email protected]" and the latter filters them to leave only those lines that contain "From:".

Upvotes: 4

JJ.
JJ.

Reputation: 5475

I really don't think you're going to be able to accomplish that with find, since find only looks for a literal match and has no ability to use wildcards or regular expressions.

If you have the option, you can install the UnxUtils package and use grep to do it. It's a port of common Unix Utilities to Win32. You can find it at: [http://unxutils.sourceforge.net/][1]

You'd then issue a grep command like this:

grep "From.*me\@my\.com" abc.txt

Hope that helps!

Upvotes: 0

Related Questions