empty lines in .csv file when running batch script

My csv file is showing blank lines in between of each output, anyway to get rid of this? my code is below.
Thank you!

@echo off
setlocal EnableDelayedExpansion

set listfile=C:\machines.txt
set outputfile=C:\dell\%computername%.csv

(
  for /F "usebackq" %%i in ("%listfile%") do (
    for /f "skip=2 tokens=2 delims=," %%A in ('wmic /node:%%i computersystem get name /format:csv 

2^>NUL') do (
      echo ComputerSystem : %%A  
  )
 for /f "skip=2 tokens=2 delims=," %%A in ('wmic /node:%%i Cpu get Name /format:csv 2^>NUL') do ( 
echo Cpu : %%A
    )
    for /f "skip=2 tokens=2 delims=," %%A in ('wmic /node:%%i path win32_VideoController get name 

/format:csv 2^>NUL') do (
      echo VideoController: %%A
    )
    for /f "skip=2 tokens=2 delims=," %%A in ('wmic /node:%%i ComputerSystem get 

TotalPhysicalMemory /format:csv 2^>NUL') do (

      set TotalPhysicalMemory=%%A
      set TotalPhysicalMemory=!TotalPhysicalMemory:~0,-10!
            echo  TotalPhysicalMemory=!TotalPhysicalMemory! MB
    
    )
    echo Drives:
    for /f "skip=2 tokens=2-4 delims=," %%A in ('wmic /node:%%i LogicalDisk Where DriveType^=3 Get 

Caption^,FreeSpace^,Size /format:csv 2^>NUL') do (
      set Caption=%%A
      set Free=%%B
      set Size=%%C
      set Free=!Free:~0,-10!
      set Size=!Size:~0,-10!
     echo !Caption!, Free=!Free! MB, Size=!Size! MB
echo --------------------------------------------------------------------------------
    )
  ) 
) > "%outputfile%"

Open in new window

lo ahmedSystem AdministratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
Okay, because the WMIC output is a little odd, adding some extra line feeds where we don't really want them, a technique that is used is to pass the output of the WMIC command through a second FOR /F command, which will remove the extra line feeds.  Makes the code a bit longer, but gets the result you want.

I also noticed you changed this:

set Free=!Free:~0,-9!
set Size=!Size:~0,-9!
echo !Caption!, Free=!Free! GB, Size=!Size! GB

to this:

set Free=!Free:~0,-10!
set Size=!Size:~0,-10!
echo !Caption!, Free=!Free! MB, Size=!Size! MB

If you really wanted MB instead of GB then that is wrong.  It would need to be:

set Free=!Free:~0,-6!
set Size=!Size:~0,-6!
echo !Caption!, Free=!Free! MB, Size=!Size! MB

The -9, -10, and -6 are telling the SET command to remove the rightmost 9, 10 or 6 characters.  So in the case of a large number, it has the following effect:

set n=12345678901
echo !n:~0,-9!
echo !n:~0,-10!
echo !n:~0,-6!

produces:

12
1
12345

Each position removed from the right is the same as dividing by 10.  So removing 2 positions is the same as dividing by 100, etc.  As a result, to get GB you need to remove 9 positions, and to get MB you need to remove 6 positions.

@echo off
setlocal EnableDelayedExpansion

set listfile=C:\machines.txt
set outputfile=C:\dell\%computername%.csv

(
    for /F "usebackq" %%i in ("%listfile%") do (
        for /f "skip=2 tokens=*" %%w in ('wmic /node:%%i computersystem get name /format:csv 2^>NUL') do (
            for /f "tokens=2 delims=," %%A in ("%%w") do (
                echo ComputerSystem : %%A
            )
        )

        for /f "skip=2 tokens=*" %%w in ('wmic /node:%%i Cpu get Name /format:csv 2^>NUL') do ( 
            for /f "tokens=2 delims=," %%A in ("%%w") do (
                echo Cpu : %%A
            )
        )
    
        for /f "skip=2 tokens=*" %%w in ('wmic /node:%%i path win32_VideoController get name /format:csv 2^>NUL') do (
            for /f "tokens=2 delims=," %%A in ("%%w") do (
                echo VideoController: %%A
            )
        )

        for /f "skip=2 tokens=*" %%w in ('wmic /node:%%i ComputerSystem get TotalPhysicalMemory /format:csv 2^>NUL') do (
            for /f "tokens=2 delims=," %%A in ("%%w") do (
                set TotalPhysicalMemory=%%A
                set TotalPhysicalMemory=!TotalPhysicalMemory:~0,-9!
                echo TotalPhysicalMemory=!TotalPhysicalMemory! GB
            )
        )

        echo Drives:
        for /f "skip=2 tokens=*" %%w in ('wmic /node:%%i LogicalDisk Where DriveType^=3 Get Caption^,FreeSpace^,Size /format:csv 2^>NUL') do (
            for /f "tokens=2-4 delims=," %%A in ("%%w") do (
                set Caption=%%A
                set Free=%%B
                set Size=%%C
                set Free=!Free:~0,-9!
                set Size=!Size:~0,-9!
                echo !Caption!, Free=!Free! GB, Size=!Size! GB
                echo --------------------------------------------------------------------------------
            )
        )
    ) 
) > "%outputfile%"

Open in new window


»bp
lo ahmedSystem AdministratorAuthor Commented:
i apologize, i sent you the test code i was using for something, my current code is actually using GB. So i should add another for command to get rif of these lines?

thank you

 
@echo off
setlocal EnableDelayedExpansion

set listfile=C:\machines.txt
set outputfile=C:\dell\%computername%.csv

(
  for /F "usebackq" %%i in ("%listfile%") do (
    for /f "skip=2 tokens=2 delims=," %%A in ('wmic /node:%%i computersystem get name /format:csv 

2^>NUL') do (
      echo ComputerSystem : %%A  
  )
 for /f "skip=2 tokens=2 delims=," %%A in ('wmic /node:%%i Cpu get Name /format:csv 2^>NUL') do ( 
echo Cpu : %%A
    )
    for /f "skip=2 tokens=2 delims=," %%A in ('wmic /node:%%i path win32_VideoController get name 

/format:csv 2^>NUL') do (
      echo VideoController: %%A
    )
    for /f "skip=2 tokens=2 delims=," %%A in ('wmic /node:%%i ComputerSystem get 

TotalPhysicalMemory /format:csv 2^>NUL') do (

      set TotalPhysicalMemory=%%A
      set TotalPhysicalMemory=!TotalPhysicalMemory:~0,-10!
            echo  TotalPhysicalMemory=!TotalPhysicalMemory! GB
    
    )
    echo Drives:
    for /f "skip=2 tokens=2-4 delims=," %%A in ('wmic /node:%%i LogicalDisk Where DriveType^=3 Get 

Caption^,FreeSpace^,Size /format:csv 2^>NUL') do (
      set Caption=%%A
      set Free=%%B
      set Size=%%C
      set Free=!Free:~0,-10!
      set Size=!Size:~0,-10!
     echo !Caption!, Free=!Free! GB, Size=!Size! GB
echo --------------------------------------------------------------------------------
    )
  ) 
) > "%outputfile%"

Open in new window

Bill PrewIT / Software Engineering ConsultantCommented:
Just adapt the changes I made to what you posted to what you need it in...


»bp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lo ahmedSystem AdministratorAuthor Commented:
Great, this works. Thank you!
Bill PrewIT / Software Engineering ConsultantCommented:
Welcome.


»bp
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.