Batch file 值大于0的输出
我想使用以下脚本输出计数:Batch file 值大于0的输出,batch-file,count,find,output,Batch File,Count,Find,Output,我想使用以下脚本输出计数: @find /c /i "Error : -2" "\\Sc0320svr0001\e$\Users\SC0320POS0003\E2ELOGS\*.dbg" >>output.txt 但是,我只想导出大于0的值 这项工作目前产出: ---------- \\SC0320SVR0001\E$\USERS\SC0320POS0003\E2ELOGS\PED_20140812_092355.DBG: 4 Findstr开关对find有不同的含义 &
@find /c /i "Error : -2" "\\Sc0320svr0001\e$\Users\SC0320POS0003\E2ELOGS\*.dbg" >>output.txt
但是,我只想导出大于0的值
这项工作目前产出:
---------- \\SC0320SVR0001\E$\USERS\SC0320POS0003\E2ELOGS\PED_20140812_092355.DBG: 4
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.
&在一行上分隔命令。
&&仅当上一个命令的errorlevel为0时才执行此命令。
||(上面未使用)仅当上一个命令的errorlevel不是0时才执行此命令
>输出到文件
>>将输出附加到文件
<从文件输入
|将一个命令的输出转换为另一个命令的输入
^如果需要传递给程序,则转义上述任何一项,包括转义本身
“带空格的参数必须用引号括起来
%variablename%a内置或用户设置的环境变量
!variablename!用户设置的环境变量在执行时展开,并使用SelLocal EnableDelayedExpansion命令打开
%<number>(%1)传递给批处理文件的第n个命令行参数
%或%%(%A或%%A)for循环中的变量。在命令提示下单%s签名,在批处理文件中双%s签名。
尝试测试输出的最后一个字符:
@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
)
太棒了!谢谢!
@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
)