Multiple Variables Outputted in Table Format

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mastermindg
Posts: 2
Joined: 10 Mar 2009 13:31

Multiple Variables Outputted in Table Format

#1 Post by mastermindg » 10 Mar 2009 16:02

I've got multiple variables that I'm pulling from multiple text files in multiple locations. What I'd like to do is to put the location and variables in a table so that it is easily read:

Code: Select all

FOR /F %%a IN ('TYPE input.txt') DO (
   for /f "tokens=2-4 delims=/ " %%b in ('TYPE E:\temp\%%a\cpu.txt') do (
      set CPUPercent_Used=%%d
   )
   for /f "tokens=2-4 delims=/ " %%c in ('TYPE E:\temp\%%a\memory.txt') do (
      set MEMPercent_Used=%%e
   )
   for /f "tokens=2-4 delims=/ " %%b in ('TYPE E:\temp\%%a\cspace.txt') do (
      set CDISK=%%d%%%
   )
   for /f "tokens=2-4 delims=/ " %%b in ('TYPE E:\temp\%%a\dspace.txt') do (
      set DDISK=%%d%%%
   )
@echo %%a   %CPUPercent_Used%   %MEMPercent_Used%   %CDISK%      %DDISK%
)


The problem with this is that the variables only take the value of the last iteration of the loop, so the values with show in a table but all the values are taken from the last lines in input.txt. How can I code this so that the values are written for each iteration?

mastermindg
Posts: 2
Joined: 10 Mar 2009 13:31

#2 Post by mastermindg » 10 Mar 2009 17:35

I figured it out:

Code: Select all

For /F "tokens=1*" %%i in (input.txt) do call :doSomething "%%i"
goto :eof

:dosomething
Set myvariable=%~1
for /f "tokens=2-4 delims=/ " %%b in ('TYPE E:\temp\%myvariable%\cpu.txt') do (
      set CPUPercent_Used=%%d
   )
   for /f "tokens=2-4 delims=/ " %%c in ('TYPE E:\temp\%myvariable%\memory.txt') do (
      set MEMPercent_Used=%%e
   )
   for /f "tokens=2-4 delims=/ " %%b in ('TYPE E:\temp\%myvariable%\cspace.txt') do (
      set CDISK=%%d%%%
   )
@echo %myvariable% %CPUPercent_Used%   %MEMPercent_Used%   %CDISK%

Post Reply