【问题标题】:How do I make findstr show the full file path inline?如何使 findstr 显示完整的文件路径内联?
【发布时间】:2015-05-30 06:13:41
【问题描述】:

当我使用grep 时,我会得到一个匹配结果列表以及所有子子目录的完整文件路径。

当我使用 findstr 执行此操作时 - 我没有得到内联结果。

我的问题是:如何让findstr 内联显示完整的文件路径?

【问题讨论】:

    标签: command-line path grep dos findstr


    【解决方案1】:

    阅读 FINDSTR 输出,在 Dave Benham 又名 dbenham 的综合 List of undocumented features and limitations of FINDSTR 中:

    ... 打印时,文件名将始终包含任何路径 提供的信息。如果 使用/S 选项。打印的路径总是相对 提供的路径,如果没有提供,则相对于当前目录。

    因此,提供绝对路径。例如:而不是

    findstr /S /M /I /C:"string being searched for" *.txt
    

    使用

    findstr /S /M /I /C:"string being searched for" "%CD%\*.txt"
    

    当然,上面例子中给出的所有/S /M /I /C:开关都是可选的

    d:\bat\files>findstr "success" *.txt
    netuser.txt:The command completed successfully.
    typeperf.txt:The command completed successfully.
    
    d:\bat\files>findstr "success" "%CD%\*.txt"
    d:\bat\files\netuser.txt:The command completed successfully.
    d:\bat\files\typeperf.txt:The command completed successfully.
    

    【讨论】:

    • 一个指向原始报价的链接会很好,这是 SS64 获得信息的地方。特别是因为原始帖子在 StackOverlow - stackoverflow.com/q/8844868/1012053.
    • 另外,我相信 OP 希望在每个匹配行之前加上文件名前缀,这将排除 /M 选项。
    • @dbenham 请原谅我对引用来源的黑暗;在/M 开关上查看我的编辑:)
    【解决方案2】:
    findstr "search string" %cd%\*
    

    【讨论】:

      猜你喜欢
      • 2020-05-30
      • 1970-01-01
      • 2011-11-10
      • 1970-01-01
      • 2012-12-02
      • 2014-02-13
      • 2012-12-05
      • 2012-05-14
      • 1970-01-01
      相关资源
      最近更新 更多