我想用以下脚本输出一个计数:
@find /c /i "Error : -2" "\\Sc0320svr0001\e$\Users\SC0320POS0003\E2ELOGS\*.dbg" >>output.txt
但是,我只想导出大于0的值。
目前输出:
---------- \\SC0320SVR0001\E$\USERS\SC0320POS0003\E2ELOGS\PED_20140812_092355.DBG: 4
答案 0 :(得分:1)
尝试测试输出的最后一个字符:
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('find /c /i "Error : -2" "\\Sc0320svr0001\e$\Users\SC0320POS0003\E2ELOGS\*.dbg"') do (
set "$line=%%a"
set "$lastchar=!$line:~-1!"
if !$lastchar! gtr 0 echo %%a >>output.txt
)
答案 1 :(得分:0)
@find /c /i "Error : -2" "\\Sc0320svr0001\e$\Users\SC0320POS0003\E2ELOGS\*.dbg" |findstr /i /v /c:": 0">>output.txt
Findstr
个开关与find
具有不同的含义。
& seperates commands on a line. && executes this command only if previous command's errorlevel is 0. || (not used above) executes this command only if previous command's errorlevel is NOT 0 > output to a file >> append output to a file < input from a file | output of one command into the input of another command ^ escapes any of the above, including itself, if needed to be passed to a program " parameters with spaces must be enclosed in quotes %variablename% a inbuilt or user set environmental variable !variablename! a user set environmental variable expanded at execution time, turned with SelLocal EnableDelayedExpansion command %<number> (%1) the nth command line parameter passed to a batch file % or %% (%A or %%A) the variable in a for loop. Single % sign at command prompt and double % sign in a batch file.