Windows 批处理 : for and findstr to include and exclude from results

标签 windows batch-file findstr

我有一个正在迭代的字符串列表,我需要在后续处理中排除某些字符串并包含其他字符串。 像这样:

listmystuff | for /F "usebackq" %%D in (`findstr /r "something*" ^| findstr /v "but not thisstuff"`)  do interestingthing

这是错误的。起作用的是拥有 findstr 之一,但不是两者。 什么是对的?

最佳答案

您需要管道 |,而不是条件命令连接 &&。管道字符必须转义。

您只需要在整个命令周围使用一组单引号。 (或者反引号,如果使用 usebackq 选项)

如果在批处理文件中使用,则需要将百分比加倍。

你的初始 FINDSTR 需要一个文件规范来搜索(或者数据通过管道传输到它)

for /f "options" %%D in ('findstr "something" fileSpec ^| findstr /v "butNotThis"') do myThing

关于Windows 批处理 : for and findstr to include and exclude from results,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21563984/

相关文章:

c++ - 如何将 C++ 对象传递给 NPAPI 插件?

c++ - 从外部应用程序附加子窗口时的消息循环(泵)

windows - 用于检查系统服务是否正在运行的批处理文件

windows - 如何使用 windows Batch 存储超过 9 个参数

svn - 如何使用findstr,在gvim中排除svn目录

cmd - CMD 中的 FINDSTR - 仅整个单词

batch-file - Grep 批量 ping

c++ - 在创建线程时无法理解此错误

android - aapt.exe在android中的作用是什么?

batch-file - 批量击键