|
Answer» Hello all,
I am a newbie to the batch scripting and I need some suggestions to get my batch file code as minimum as possible.
I have a text file names "runs.log" which contains some numbers, like this:
0 12 634 194 1781 63
What I need is the batch SCRIPT will open the file and summarize all the numbers and give me the result.
I am trying to use the FOLLOWING code, but its not working
for /F %%a in (runs.log) do ( set /P MR= set /a DAILY=%%a+%MR%\ echo %DAILY%>MONTHLY_RUN.tmp )
Thanks to any kind of helpThere are a few things I can see here. First, your code seems to be doing more than just giving you the result, which BEGS the question "Are you gathering a daily runs.log and adding it to a monthly rather than just gathering a daily total?" To do what you originally asked for which is to summarize what is in the runs.log file. try this:
Code: [Select]for /f %%a in (runs.log) do (set /a total+=%%a) That will give you a total of your runs.log, which, if that is your daily total, can then be added to your monthly total and the log. I'm curious as to how this all interplays with eachother. To me it seems the runs.log keeps some sort of running tally of instances, and then you are trying to add the daily total to your monthly total and keep a log of how things are progressing. If that is in fact the case, try this:
Code: [Select]echo off for /f %%A in (MONTHLY_RUN.log) do (set MR=%%A) for /f %%B in (runs.log) do (set /a total+=%%B) set /a DAILY=%MR%+%total% echo %DAILY%>>MONTHLY_RUN.log
This grabs the PREVIOUS total from MONTHLY_RUN.log, adds the total from runs.log, and puts a new line with the new total back into MONTHLY_RUN.log. If that isn't what you are trying to do, then disregard. Thank you very much Raven19528 it really works.. you saved my day
|