在批处理文件中使用参数max(high)或min(low)

时间:2014-06-27 11:35:27

标签: batch-file

我想在批处理文件中使用命令,我可以找到最低价格或最高价格。

批处理文件命令:

@echo on    
echo "file init    
call ec2-describe-spot-price-history -H --instance-type t1.micro --start-time 2014-06-17T10:00:00 --end-time 2014-06-17T13:00:00 >> out.txt;    
echo "file written"    
for /f "tokens=1 delims=" %%i in (out.txt) do echo %%i    
echo "file written"    
echo "file done"
pause 

批处理文件的输出

Type    Price   Timestamp   InstanceType    ProductDescription  AvailabilityZone
SPOTINSTANCEPRICE   0.006100    2014-06-17T10:19:16+0530    t1.micro    Windows us-east-1d
SPOTINSTANCEPRICE   0.006100    2014-06-17T10:19:15+0530    t1.micro    Windows us-east-1a
SPOTINSTANCEPRICE   0.006100    2014-06-17T10:19:15+0530    t1.micro    Windows us-east-1b

任何帮助将不胜感激!!

1 个答案:

答案 0 :(得分:0)

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "max=0.000000"
SET "min=9.999999"
FOR /f "skip=1delims=" %%a IN (q24450870.txt) DO (
 FOR /f "tokens=2" %%i IN ("%%a") DO (
  IF %%i gtr !max! (SET "max=%%i"&SET "maxline=%%a")
  IF %%i lss !min! (SET "min=%%i"&SET "minline=%%a")
 )
)

ECHO max is %max% IN %maxline%
ECHO min is %min% IN %minline%
GOTO :EOF

我使用了一个名为q24450870.txt的文件,其中包含我的测试数据。

您的数据包含价格相同的三条数据行,因此结果显示为无意义。此外,显示的数据不是声明的批处理文件的输出,但可能代表数据文件的内容out.txt

如果没有进一步的信息,那么您的目标实际上就是纯粹的猜测。


使用该过程,除了使用您的最新数据之外没有变化,我获得了这个结果:

max is 0.006100 IN SPOTINSTANCEPRICE 0.006100 2014-06-29T22:45:09+0530 t1.micro SUSE Linux us-east-1b 
min is 0.002100 IN SPOTINSTANCEPRICE 0.002100 2014-06-29T22:45:08+0530 t1.micro Linux/UNIX us-east-??1b

这似乎是最大和最小,所以抱歉 - 看不到你的问题。需要更多信息。