简体   繁体   English

如何使用FINDSTR获取带有简单OR双引号的行

[英]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.

相关问题 如何删除双引号内的新行? - How to remove new lines within double quotes? 如何在python中过滤三重和双简单引号? - How to filter triple and double simple quotes in python? 管道变量到FINDSTR w /正则表达式和Escaped双引号 - Piped Variable Into FINDSTR w/ Regular Expressions and Escaped Double Quotes DOS findstr查找引号之间带有文本的所有行 - DOS findstr to find all the lines with text between quotes 如何获取带双引号的字符串并在jmeter中拆分它 - how to get a string with double quotes and split it in jmeter 如何使用正则表达式仅提取双引号、单引号之间的数字或不提取数字 - How extract only numbers between double quotes, simple quotes or without them using regex 正则表达式如何获取双引号(包括双引号)内的值 - Regular Expression how to get the value inside double quotes including double quotes 删除行中的所有空格,但不删除双引号之间的空格 - Remove all spaces in lines but not between double quotes VB.Net-使用正则表达式识别双引号之间的新行 - VB.Net - Use regular expression to identify new lines between double quotes 如何使用findstr搜索多个不同的字符串? - How to use findstr to search for multiple different strings?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM