Data Consolidation using Batch Script

January 26, 2013 at 02:41:45
Specs: Windows 7
I have following string in text files:

Hostname: ABCD
Manufacturer: LENOVO
Model: 0585AL7
Domain: XYZ.COM
Is Part of Domain: True
Current Logged In User: IN\USER
Number of Processors: 1
Operating System: Microsoft Windows 7 Enterprise
Name: Microsoft Windows 7 Enterprise |C:\Windows|\Device\Harddisk0\Partition1
Organization: XYZ
RegisteredUser: XYZ
SerialNumber: 00392-918-5000002-85350
WindowsDirectory: C:\Windows
Version: 6.1.7600
Original Install Date: 20110319025551.000000+330
I am using below command to parse the content.

FINDSTR /B /S /I "Operating System" *.txt >> OsMatch.lst
FINDSTR /B /S /I "Version" *.txt >> OsMatch.lst
FINDSTR /B /S /I "Manufacturer" *.txt >> OsMatch.lst
FINDSTR /B /S /I "Domain" *.txt >> OsMatch.lst
FINDSTR /B /S /I /C:"Is Part of Domain" *.txt >> OsMatch.lst
FINDSTR /B /S /I /C:"Current Logged In User" *.txt >> OsMatch.lst
FINDSTR /B /S /I /C:"Number of Processors" *.txt >> OsMatch.lst
FINDSTR /B /S /I "RegisteredUser" *.txt >> OsMatch.lst
FINDSTR /B /S /I "Organization" *.txt >> OsMatch.lst
FINDSTR /B /S /I "SerialNumber" *.txt >> OsMatch.lst
FINDSTR /B /S /I "WindowsDirectory" *.txt >> OsMatch.lst
FINDSTR /B /S /I /C:"Original Install Date" *.txt >> OsMatch.lst

ECHO Hostname,Operating System, Version, Manufacturer, Domain, IsPartofDomain, CurrentLoggedInUser, No of Processor,

RegisteredUser, Organization, Serial Number, WindowsDirectory, InstallDate, Location > Desktop-OS.csv

FOR /f "tokens=1,2* delims=:" %%a in (OsMatch.lst) do ( set new1=%%a
SET new2=%%c
SET new1=!new1:~0,-4!

FOR /f "tokens=1,* delims=\" %%a in ('echo !new1!') do (
SET new5=%%a
SET new6=%%b


FOR /f "tokens=* delims= " %%a in ('echo !new2!') do (
SET new4=%%a
)
)

IF {!new6!}=={} (echo !new5!,!new4!,NA >> Desktop-OS.csv
) else ( echo !new6!,!new4!,!new5! >> Desktop-OS.csv)
)
Output is coming in excel file, but in each row, I want output under every column as below

Hostname Operating System Version
ABCD Microsoft Windows 7 Enterprise 6.1.7600
likewise all the TABS
"Manufacturer Domain IsPartofDomain CurrentLoggedInUser No of Processor RegisteredUser Organization Serial Number WindowsDirectory InstallDate Location" .

Thanks in advance.. :)


See More: Data Consolidation using Batch Script

Report •

#1
January 26, 2013 at 20:16:09
Here's what I would do:
(same down to here):
set prev=
set line=
FOR /f "tokens=1,2* delims=:" %%a in (OsMatch.lst) do ( set new1=%%~pna
SET new2=%%c
rem don't need with new code: SET new1=!new1:~0,-4!
if "!prev!" neq "!new1!" (
if "!prev!" neq "" >>desktop-os.csv echo !line!,!prev!
set line=
set prev=!new1!


rem why splitting these? just lump them
rem FOR /f "tokens=1,* delims=\" %%a in ('echo !new1!') do (
rem SET new5=%%a
rem SET new6=%%b

rem also, i don't see where this does much of anything...
rem FOR /f "tokens=* delims= " %%a in ('echo !new2!') do (
rem SET new4=%%a
rem )
)

rem: And this really confuses me, since it changes the order of the data.
rem IF {!new6!}=={} (echo !new5!,!new4!,NA >> Desktop-OS.csv
rem ) else ( echo !new6!,!new4!,!new5! >> Desktop-OS.csv)
set line=!line!,!new2!
)
::===== end

rendered down:

set prev=
set line=

FOR /f "tokens=1,2* delims=:" %%a in (OsMatch.lst) do (
  set new=%%~pna
  SET new2=%%c
  if "!prev!" neq "!new1!" (
    if "!prev!" neq "" >>desktop-os.csv echo !line!!prev!
    set line=
    set prev=!new1!
  )
  set line=!line!!new2!,
)
::==== end

(not tested)

Report •
Related Solutions


Ask Question