【问题标题】:CMD Search a directory to Find a string inside a fileCMD 搜索目录以在文件中查找字符串
【发布时间】:2014-12-19 16:26:27
【问题描述】:

我需要使用 Windows CMD 提示符在具有特定字符串的目录中查找文件。

例如,我需要找到具有如下字符串的文件:

<h1>Select an Item</h1>

【问题讨论】:

    标签: cmd command-prompt


    【解决方案1】:

    “findstr”就是你要找的。​​p>

    findstr /I "<h1>Select\ an\ Item</h1>" *.*
    

    findstr 是命令,/I 是匹配字符串不区分大小写的标志。 "&lt;h1&gt;Select\ an\ Item&lt;/h1&gt;" 是您的字符串(注意转义的空格!),*.* 表示“在此目录中的所有文件中”。

    基本语法是findstr "seachString" filename.ext。 您可以将 filename.ext 替换为 *.ext*.* 以过滤 cretin 文件类型或查看所有文件。 这只会在当前目录中查找,而不是递归查找。

    更多关于命令findstr documentation 的信息

    【讨论】:

      【解决方案2】:

      您需要的命令基本上是findstr

      输入

      findstr /?
      

      在提示指示时。

      可能对你有用的命令是

      findstr /m /g:"a file containing your string or strings" *
      

      findstr /m /L /c:"<h1>Select an Item</h1>" *
      

      可能需要对"quoted string" 的内容进行一些实验,尤其是对&lt;&gt;() 和其他对cmd.exe 具有特殊意义的字符行。

      【讨论】:

        猜你喜欢
        • 2021-10-18
        • 2011-08-14
        • 1970-01-01
        • 1970-01-01
        • 2012-05-22
        • 1970-01-01
        • 1970-01-01
        • 2010-12-03
        相关资源
        最近更新 更多