【问题标题】:Batch Scripting to Search text with space in a .log file用于在 .log 文件中搜索带空格的文本的批处理脚本
【发布时间】:2013-07-02 08:21:03
【问题描述】:

我想在日志文件中搜索文本。
如果发现显示错误和文本。
否则显示未找到和文本。

set str2=Testing Failed in env
findstr "%str2%" SystemOut.log >nul
if not errorlevel 1 ( echo                  ERROR: Testing Failed in env)
if errorlevel 1 ( echo Not Found                             Testing Failed in env!)

每当在日志文件中遇到测试时,它都会显示错误,但它不应该那样做。 当我尝试通过添加引号或某些内容进行更改时,通过了肯定条件但否定条件失败。

请帮我写剧本。

谢谢,
马赫帕特尔

【问题讨论】:

    标签: search text batch-file space


    【解决方案1】:

    您需要 /c: 开关以在文字模式中包含空格。

    @echo off
    set str2=Testing Failed in env
    findstr /c:"%str2%" SystemOut.log >nul
    if errorlevel 1 ( echo Not Found        "%str2%")
    if not errorlevel 1 ( echo found "%str2%")
    

    【讨论】:

      猜你喜欢
      • 2022-11-28
      • 2010-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-14
      相关资源
      最近更新 更多