简体   繁体   English

使用FIND命令使用cmd.exe从一行中查找两个字符串

[英]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? 如何使用FIND(cmd.exe默认命令)从文件安全地检测以下字符串,而名称minnie可以是任何东西? its just that FROM: line has me@my.com on it. 它只是FROM:行上有me@my.com。

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

it should not be mixed to this TO line : 不应混入此TO行:

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:". 前者搜索包含“ me@my.com”的所有行,后者过滤它们以仅保留那些包含“ From:”的行。

You can use findstr instead of find which has more advanced capabilities, like regular expression matching. 您可以使用findstr代替具有更高级功能(例如正则表达式匹配)的find

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. 至少从Windows 2000开始,默认情况下还包括findstr

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. 我真的不认为您将无法使用find来完成此任务,因为find仅查找文字匹配项,而不能使用通配符或正则表达式。

If you have the option, you can install the UnxUtils package and use grep to do it. 如果您有此选项,则可以安装UnxUtils软件包并使用grep进行安装。 It's a port of common Unix Utilities to Win32. 这是Win32常用Unix实用程序的端口。 You can find it at: [ http://unxutils.sourceforge.net/][1] 您可以在以下位置找到它:[ http://unxutils.sourceforge.net/] [1 ]

You'd then issue a grep command like this: 然后,您将发出一个grep命令,如下所示:

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

Hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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