Click here for important information about

Batch file to average up numbers in a column

December 6, 2011 at 14:12:25
Specs: Win7, 4gb
Does anyone know how to use a batch file to average up numbers in a column:


and then do the following arithmetic on it.


As you may have figured out, the number is time in microseconds and I need to convert it to hh:mm:ss. I have done it in Excel but the Win2008 server where the logs reside don't have Office installed.

Thanks in advance!


See More: Batch file to average up numbers in a column

December 6, 2011 at 17:15:44
AFAIK this cannot be achieved in a strictly batch script as batch scripts cannot handle floating point math so the results may not be precise. A batch script/VB script hybrid could be the answer but I am not familiar enough with Win2008 Server commands to be sure.

You could test this script, no warranties. You didn't give any details of what the input file looked like, number of columns, column number to be added etc, so I simply saved the data you supplied to the trial.txt file for preliminary testing purposes.

@echo off
setlocal enabledelayedexpansion 
echo wscript.echo eval(wscript.arguments(0))>%temp%\evaluate.vbs

for /f %%1 in (trial.txt) do (
    set /a total=!total!+%%1
    set /a count+=1

set calc=%total%/%count%
call :calculate
set Average=%result%

set calc=(%average%/60000)/(24*60)
call :calculate
set Final=%result%

echo Average=%Average%
echo Final Result=%Final%

del %temp%\evaluate.vbs

exit /b

for /f %%1 in ('cscript //nologo %temp%\evaluate.vbs "%calc%"') do (

    set result=%%1


Please come back & tell us if your problem is resolved.

Report •
Related Solutions

Ask Question