Search code examples
parsingbatch-filecmdsystem-information

How do I parse info from a command and output it?


I haven't written a batch file for a few years, and I've forgotten how to do this. My code displays the OS Name.

Code:

systeminfo | findstr /B /C:"OS Name"

It then says

OS Name: Microsoft Windows 8.1

(there is a huge space in between)

I want it to display the OS Name without actually outputting "OS Name:" and have the huge space. Any help is greatly appreciated.


Solution

  • Here's one way:

    @echo off
    for /f "tokens=1,2,*" %%a in ('systeminfo ^| findstr /B /C:"OS Name" ') do echo "%%c"