代码之家  ›  专栏  ›  技术社区  ›  Gauthier

连接到findstr输入的管道

  •  13
  • Gauthier  · 技术社区  · 14 年前

    宏的名称在 C:\temp\macros.txt

    type C:\temp\macros.txt 在命令提示符下打印列表。

    现在我想把这个输出传输到 findstr .

    type C:\temp\macros.txt | findstr *.ss (ss是我要查找宏名称的文件类型)。

    这似乎不起作用,我没有得到任何结果(非常快,似乎根本没有尝试)。 findstr <the first row of the macro list> *.ss 确实有效。

    我也试过了 findstr *.ss < c:\temp\macros.txt

    1 回复  |  直到 14 年前
        1
  •  19
  •   Joey Gumbo    14 年前

    findstr 作品。它以文件名(模式)或stdin的形式获取输入(在非要查找的内容中查找内容),但您要查找的内容是 总是 在命令行上作为参数提供给 findstr公司

    findstr foo xyz.txt
    

    查找字符串 foo xyz.txt .

    type meh.txt | findstr x
    

    查找字符串 x 在上一个命令的输出中(在本例中是文件的内容 meh.txt 浪费时间 type 命令,非常类似于对 cat ).

    既然你是在追求 我建议使用不同的方法,而不是宏名称出现在实际的行中。这假设包含宏的文件每行列出一个宏:

    for /f "delims=" %x in (macros.txt) do @(echo %x: & find /c "%x" *.ss)
    

    这个 for find /c 它实际上计算匹配线。