Board logo

标题: [文本处理] [已解决]批处理如何根据指定条件提取回显中的内容? [打印本页]

作者: chouxia    时间: 2016-1-5 10:27     标题: [已解决]批处理如何根据指定条件提取回显中的内容?

回显内容类似这样:
job=20160105102433
progress=0
status=run
id=22
需求是:
对比job,一致的话分析progress值, 小于10且status为run的时候
回显job    progress    id
作者: gawk    时间: 2016-1-5 10:35

请举例说明什么是“job一致”
作者: chouxia    时间: 2016-1-5 10:39

回复 2# gawk


    这是个子过程, 进入子过程之前会取得一个job值。
这个值会和子过程取到的值比较,只有一致的才会继续执行
作者: 回家路上    时间: 2016-1-5 10:54

  1. set new=你好,我是新来的,前来拜会...
  2. if "%new%" neq "" if "%job%"=="%new%" if %progress% lss 10 if "%status%"=="run" (
  3.         echo;%job%    %progress%    %id%
  4. )
复制代码

作者: gawk    时间: 2016-1-5 14:42

  1. @echo off
  2. REM 进入子过程之前会取得一个job值
  3. set OldJob=20160105102433
  4. REM 用 type "1.txt" 模拟回显
  5. type "1.txt" | findstr "^job=%OldJob%$" >nul 2>&1
  6. if errorlevel 1 (
  7.     echo job不一致
  8.     goto :eof
  9. ) else (
  10.     type "1.txt" | findstr "^status=run$" >nul 2>&1
  11.     if errorlevel 1 (
  12.         echo status不是run
  13.         goto :eof
  14.     ) else (
  15.         for /f "tokens=2 delims==" %%i in ('type "1.txt" ^| findstr "progress="') do (
  16.             if %%i lss 10 (
  17.                 type "1.txt" | findstr "job= progress= id="
  18.             ) else (
  19.                 echo progress不小于10
  20.             )
  21.         )
  22.     )
  23. )
  24. pause
复制代码

作者: flyinnet9    时间: 2016-1-5 16:21

综合4、5楼的水一个
  1. @echo off
  2. REM 进入子过程之前会取得一个job值
  3. set OldJob=20160105102433
  4. REM 用 type "1.txt" 模拟回显
  5. for /f %%a in ('type 1.txt') do set %%a
  6. if "%job%"=="%oldjob%" if %progress% lss 10 if "%status%"=="run" echo.%job% %progress% %id%
复制代码

作者: chouxia    时间: 2016-1-6 08:32

根据回显内容的顺序,我用if 变量==值的方式进行了回显读取和判断




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2