简体   繁体   中英

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 me@my.com on it.

From: "Minnie" <me@my.com>

it should not be mixed to this TO line :

To: <me@my.com>

eg this batch file row does not work properly :

find "me@my.com" abc.txt

Try two pipelined find commands, like this:

find "me@my.com" abc.txt | find "From:"

The former searches for all lines containing "me@my.com" and the latter filters them to leave only those lines that contain "From:".

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

findstr /r /c:"^From:.*<me@my.com>" 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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM