我在文本文件中有以下字符串:
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
我使用下面的命令来解析内容。
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)
)
输出来自excel文件,但在每一行中,我希望在每列下输出
Hostname Operating System Version
ABCD Microsoft Windows 7 Enterprise 6.1.7600
同样是所有TABS
“制造商域IsPartofDomain CurrentLoggedInUser处理器注册用户组织序列号WindowsDirectory InstallDate位置”
提前致谢.. :))