如何使用 wmic 生成包含多列的 txt
How to use wmic in order to generate a txt with many columns
我正在使用
wmic qfe get HotFixID >> WindowsUpdateVersion.txt
为了导出 KB{num} 的列表。我正在寻找一个命令来在许多列(3 或 4 列,.txt 或 .xls,不重要)中重塑此列表。
我已经尝试过
wmic qfe get HotFixID /format:* >> WindowsUpdateVersion.txt
*(每个 WMIC 样式表)
但其中 none 似乎工作正常。
有什么想法吗?
非常感谢!
已编辑:处理任何少于 full
行的尾随行
这会用 ascii 数据创建 file.txt
,然后用 4 列写入 file2.txt
。
任何包含 !
的行都是错误的 - 如果有人想在其他情况下应用它。
@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
我正在使用
wmic qfe get HotFixID >> WindowsUpdateVersion.txt
为了导出 KB{num} 的列表。我正在寻找一个命令来在许多列(3 或 4 列,.txt 或 .xls,不重要)中重塑此列表。 我已经尝试过
wmic qfe get HotFixID /format:* >> WindowsUpdateVersion.txt
*(每个 WMIC 样式表)
但其中 none 似乎工作正常。
有什么想法吗?
非常感谢!
已编辑:处理任何少于 full
行的尾随行
这会用 ascii 数据创建 file.txt
,然后用 4 列写入 file2.txt
。
任何包含 !
的行都是错误的 - 如果有人想在其他情况下应用它。
@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