[英]How to use FINDSTR to get lines with simple OR double quotes
I'm trying to get lines from files in a directory tree with a single or double quote in them. 我正在尝试从目录树中的文件中获取带有单引号或双引号的行。 As an example, I want to get these lines with a single findstr command:
举个例子,我想用一个findtr命令来获取这些行:
You should be able to get a "Hello world" program really quick.
Enter a value for params 'name' and 'age', please.
If no value is entered for 'name' param, the "Hello world" program will throw an exception.
I can get lines with only single quotes ( findstr /srn \\' *.txt
), only double quotes ( findstr /srn \\^" *.txt
), or both single and double quotes ( findstr /srn \\'\\^" *.txt
), but I need lines with single or double quotes with only a single command. 我只能使用单引号(
findstr /srn \\' *.txt
),只能使用双引号( findstr /srn \\^" *.txt
),或单引号和双引号( findstr /srn \\'\\^" *.txt
),但我需要只有一个命令的带单引号或双引号的行。
Any idea about how to achieve it? 有关如何实现它的任何想法?
Explosion Pills had the correct idea, but not the correct syntax. Explosion Pills有正确的想法,但没有正确的语法。
It can get tricky when trying to escape the quote for both FINDSTR and for the CMD parser. 当试图逃避FINDSTR和CMD解析器的引用时,它会变得棘手。 The regex you want is
['\\"]
, but then you need to escape the "
for the CMD parser. 你想要的正则表达式是
['\\"]
,但是你需要转义"
为CMD解析器。
This will work: 这将有效:
findstr /srn ['\^"] *.txt
and so will this 这样的话
findstr /srn "['\"]^" *.txt
and so will this 这样的话
findstr /srn ^"['\^"]^" *.txt
NOTE 注意
You are at risk of failing to find files that contain the string because of a nasty FINDSTR bug. 由于一个令人讨厌的FINDSTR错误,您有可能无法找到包含该字符串的文件。 The
/S
option may fail to find files if 8.3 short names are enabled and a folder contains a file with an extension longer than 3 chars that starts with .txt
. 如果启用了8.3短名称且文件夹包含扩展名超过3个以
.txt
开头的字符的文件,则/S
选项可能无法找到文件。 ( name.txt2
for example). (例如
name.txt2
)。 For more information, see the section labeled BUG - Short 8.3 filenames can break the /D and /S options at What are the undocumented features and limitations of the Windows FINDSTR command? 有关详细信息,请参阅标记为BUG的部分- 短8.3文件名可以打破/ D和/ S选项 Windows FINDSTR命令的未记录功能和限制是什么? .
。
使用字符类
findstr /srn ['\^"] *.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.