Search code examples
batch-filewmictext-manipulationqfe

How to use wmic in order to generate a txt with many columns


I'm using

    wmic qfe get HotFixID >> WindowsUpdateVersion.txt

in order to export a list of KB{num}. I am looking for a command to reshape this list in many columns (3 or 4 columns, .txt or .xls, not important). I have already tried with

   wmic qfe get HotFixID /format:* >> WindowsUpdateVersion.txt

* (every WMIC Stylesheets)
but none of them seem to work properly.
Any ideas?
Thanks so much!


Solution

  • EDITED: to process any trailing lines of less than full lines

    This creates file.txt with the ascii data and then writes file2.txt with the 4 columns.

    Any lines containing ! will be wrong - if someone wants to apply this in another situation.

    @echo off
    (
     for /f "skip=1 delims=" %%a in ('wmic qfe get HotFixID') do (
       for /f %%b in ("%%a") do echo %%~b
     )
    )>file.txt
    
    setlocal enabledelayedexpansion
    set a=
    set c=
    (
     for /f "usebackq delims=" %%a in ("file.txt") do (
      set a=!a! %%a
      set /a c+=1
      if !c! EQU 4 (
         echo !a:~1!
         set a=
         set c=
      )
     )
    if not "!a!"=="" echo !a:~1!
    )>file2.txt