2

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:

  • 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.

Any idea about how to achieve it?

4

2 回答 2

4

Explosion Pills 有正确的想法,但语法不正确。

当试图为 FINDSTR 和 CMD 解析器转义引号时,它会变得很棘手。你想要的正则表达式是['\"],但是你需要"为 CMD 解析器转义。

这将起作用:

findstr /srn ['\^"] *.txt

这也会

findstr /srn "['\"]^" *.txt

这也会

findstr /srn ^"['\^"]^" *.txt


注意
由于令人讨厌的 FINDSTR 错误,您可能无法找到包含该字符串的文件。/S如果启用了 8.3 短名称并且文件夹包含扩展名超过 3 个字符且以 . 开头的文件,该.txt。(name.txt2例如)。有关详细信息,请参阅标有​​BUG - Short 8.3 filenames can break the /D 和 /S 选项部分,Windows FINDSTR 命令有哪些未记录的功能和限制?.

于 2013-05-28T14:51:50.670 回答
1

使用字符类

findstr /srn ['\^"] *.txt
于 2013-05-27T15:57:10.473 回答