The Scenario:
I am trying to reformat an output of an application (Wpkg, command wpkg.js /query:a). I am limited to standard commandline tools.
The command output consists of repetitive blocks of software package title and it's parameters, ie.:
Mozilla Firefox
ID: mozilla-firefox
Revision: 23.0.1.1
Reboot: false
Execute: -
Priority: 100
Status: Installed
Mozilla Thunderbird
ID: mozilla-thunderbird
Revision: 17.0.8.1
Reboot: false
Execute: -
Priority: 100
Status: Installed
This makes a long output that is hard to read. I also do not need all the information.
Therefore I am trying, for each block, to collect interesting information in one variable which I would then output in one line, getting result like this:
Mozilla Firefox mozilla-firefox 23.0.1.1 Installed
Mozilla Thunderbird mozilla-thunderbird 17.0.8.1 Installed
The Problem:
To achieve that, I began first to parse the output using following code:
rem Split all lines into two tokens
@for /f "tokens=1,2" %%G IN ('%WPKG_CMD% /query:a') DO @(
rem With first token, check what to do:
rem I can get known strings (Store, Ignore)
rem or I can get package name (NewLine)
@set WpkgListAll_ToDo=NewLine
@if [%%G]==[ID:] set WpkgListAll_ToDo=Store
@if [%%G]==[Revision:] set WpkgListAll_ToDo=Store
@if [%%G]==[Reboot:] set WpkgListAll_ToDo=Ignore
@if [%%G]==[Execute:] set WpkgListAll_ToDo=Ignore
@if [%%G]==[Priority:] set WpkgListAll_ToDo=Ignore
@if [%%G]==[Status:] set WpkgListAll_ToDo=Store
rem Echo for debug purpose
@echo [%%G][%WpkgListAll_ToDo%]
rem Next follows some unimportant code
)
From that code above I would totally expect a following debug output:
[Mozilla][NewLine]
[Revision:][Store]
[Reboot:][Ignore]
[Execute:][Ignore]
[Priority:][Ignore]
[Status:][Store]
[Mozilla][NewLine]
[ID:][Store]
[Revision:][Store]
[Reboot:][Ignore]
[Execute:][Ignore]
[Priority:][Ignore]
[Status:][Store]
What I get though is...:
[Mozilla][]
[Revision:][]
[Reboot:][]
[Execute:][]
[Priority:][]
[Status:][]
[Mozilla][]
[ID:][]
[Revision:][]
[Reboot:][]
[Execute:][]
[Priority:][]
[Status:][]
...and I've been trying hard to understand why, but I failed.
The Question:
Can anyone explain me why the output fails me and what should I do to get it right?