Reputation: 21
Basically I generated a text file through wmic
with all of present windows updates on one of my client systems.
The text file comes up as:
HotFixID
KB3140768
KB3150513
KB...(and so on)
So, I wish to execute a command through cmd (even if I have to grab some "outside" tool to get it done), in order to remove the KB
from the beginning of each line, and leaving me only with the numbers.
I managed to "jump" the HotFixID
with:
for /f "skip=1" (...)
But I can't manage to remove the KB*
.
My idea is, to bulk remove all windows updates at once, over cmd/batch file.
Upvotes: 0
Views: 689
Reputation:
You don't need a separate text file, but can parse wmic output directly, cmd line:
> for /f "skip=1delims=KB " %A in ('wmic qfe get HotfixID') do @for /f "delims= " %B in ("%A") do @echo:%B
4100347
4343669
...
In a batch file
@Echo off
for /f "skip=1delims=KB " %%A in ('wmic qfe get HotfixID'
) do for /f "delims= " %%B in (%%A) do echo:%%B
This simple approach works as leading delimiters are ignored and
provided the content to parse doesn't contain any of the letters used as delims.
Upvotes: 2
Reputation: 5504
Here is one possible solution (for cmd):
for /f "skip=1 delims=KB" %A IN (your_file.txt) do @echo %A >> your_new.txt
For batch file you have to try:
for /f "skip=1 delims=KB" %%A IN (your_file.txt) do echo %%A >> your_new.txt
skip=1
option skips the first line of your file which is HotFixID
.
delims=KB
option doesn't parse K
and B
into tokens.
For better understanding the for
command/loop please type for /?
in a fresh cmd.
Upvotes: 1