如何在Windows 7命令提示符下的findstr命令中使用OR运算符? [英] How to use OR operator in findstr command from a windows 7 command prompt?

查看:343
本文介绍了如何在Windows 7命令提示符下的findstr命令中使用OR运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Findstr应该支持正则表达式,而我使用正则表达式的方式则需要使用 or来检查文件是否以 .exe或 .dll结尾。但是,我无法使或操作正常进行。当使用'|'窗口时,我认为我试图通过管道传递上一条命令,并且'OR'被读为字面上的OR

Findstr is supposed to support regular expressions and the way I am using it I need to have an 'or' to check if a file ends in ".exe" or ".dll". However I cannot get the or operation to work. When using '|' windows thinks I am trying to pipe the previous command and 'OR' is read as literally OR

推荐答案

< Windows system32目录中的code> findstr.exe 仅支持非常有限的一组正则表达式字符。在命令提示符窗口中运行 findstr /?会导致显示此控制台应用程序的帮助,并列出受支持的正则表达式字符及其含义。

findstr.exe in Windows system32 directory supports only a very limited set of regular expression characters. Running in a command prompt window findstr /? results in getting displayed help for this console application listing also the supported regular expression characters with their meanings.

但是正如 eryksun 在他的评论中所述,可以在命令行上指定多个搜索字符串以进行构建一个简单的OR表达式。

But as eryksun explained in his comment, multiple search strings can be specified on command line to build a simple OR expression.

如果有一个列表文件 FileNames.lst 包含例如

In case of having a list file FileNames.lst containing for example

C:\Program Files\Internet Explorer\ieproxy.dll
C:\Program Files\Internet Explorer\iexplore.exe
C:\Program Files\Internet Explorer\iexplore.exe.mui

,并且所有以 .dll .exe 不区分大小写的文件名都应通过命令输出 findstr ,获取此输出的命令行可能是:

and just all file names ending with .dll OR .exe case-insensitive should be output by command findstr, the command line for getting this output could be:

%SystemRoot%\system32\findstr.exe /I /R "\.exe$ \.dll$" FileNames.lst

输出示例 FileNames.lst 中的行:

C:\Program Files\Internet Explorer\ieproxy.dll
C:\Program Files\Internet Explorer\iexplore.exe

正则表达式搜索字符串中的空格由 findstr 解释为两个字符串之间的分隔符。因此, findstr 使用正则表达式字符串 \.dll $ \.exe $ 并返回两个表达式之一与字符串匹配的所有行。

The space in regular expression search string is interpreted by findstr as a separator between the two strings. Therefore findstr searches with the regular expression strings \.dll$ and \.exe$ and return all lines where one of the two expressions matches a string.

对两个或多个正则表达式字符串进行OR运算的另一种方法是使用参数 / C: ... 在命令行上多次,当正则表达式搜索字符串包含1个或多个空格时,这应作为搜索表达式中的文字字符。

Another method to OR two or more regular expression strings would be using parameter /C:"..." multiple times on command line which is necessary when a regular expression search string contains 1 or more spaces which should be included as literal character(s) in search expression.

%SystemRoot%\system32\findstr.exe /I /R /C:"\.dll$" /C:"\.exe$" FileNames.lst

结果与上面的相同

但是对于此特定任务,根本不需要运行正则表达式搜索,因为 findstr 还提供了参数 / E 仅返回在行末找到搜索到的字符串的行。

But for this specific task it is not necessary at all to run a regular expression search as findstr offers also the parameter /E for returning only lines where the searched strings are found at end of a line.

%SystemRoot%\system32\findstr.exe /E /I /C:.exe /C:.dll FileNames.lst

这篇关于如何在Windows 7命令提示符下的findstr命令中使用OR运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆