parse formatted data

July 27, 2010 at 13:14:27
Specs: Windows 2003
I have the followed output from the cluster resource /status command, and i need to parse the output and assign it to variables, i've tried using the for command but becuase the names can have spaces in them it trips up the delimiter.

Listing status for all available resources:

Resource Group Node Status
-------------------- -------------------- --------------- ------
Cluster IP Address Cluster Group ISRMIS21 Online
Cluster Name Cluster Group ISRMIS21 Online
Disk Q: Cluster Group ISRMIS21 Online
Oracle Services for MSCS Cluster Group ISRMIS21 Online
Disk S: SQL Server ISRMIS21 Online
SQL Network Name (ISRSQLx64CLUS) SQL Server ISRMIS21 Online
SQL IP Address 1 (ISRSQLx64CLUS) SQL Server ISRMIS21 Online

i need to end up with

echo ResourceName = Cluster IP Address
echo GroupName = Cluster Group
echo NodeName = ISRMIS21
echo ResourceStatus = Online

any help would be most greatful,
Whiskie


See More: parse formatted data

Report •


#1
July 27, 2010 at 17:15:41
is that the actual input source? show an actual input source .If you have IP addresses, show them. Of course, you can provide fake IP addresses, but at least show them in digits form. Show your desired output as well

GNU win32 packages | Gawk


Report •

#2
July 28, 2010 at 00:13:30
Yes, The source command is

c:\>cluster resource /status

Listing status for all available resources:

Resource Group Node Status
-------------------- -------------------- --------------- ------
Cluster IP Address Cluster Group ISRMIS21 Online
Cluster Name Cluster Group ISRMIS21 Online
Disk Q: Cluster Group ISRMIS21 Online
Oracle Services for MSCS Cluster Group ISRMIS21 Online
Disk S: SQL Server ISRMIS21 Online
SQL Network Name (ISRSQLx64CLUS) SQL Server ISRMIS21 Online
SQL IP Address 1 (ISRSQLx64CLUS) SQL Server ISRMIS21 Online

but i need it each row into the following block

echo ResourceName = Cluster IP Address
echo GroupName = Cluster Group
echo NodeName = ISRMIS21
echo ResourceStatus = Online

I got this far with my script, but the spaces between the names confuse the delimiter. this messes up the assigning the variables at the end. Note that this out can be variable in the number of rows

For /f "usebackq skip=4 tokens=* " %%i IN (`cluster resource /status`) DO (
Set strArrayValue=%%i
call:functionArray
)

rem set strArrayName

For /f "usebackq tokens=1-9 delims==. " %%i IN (`set strArrayName`) DO (

rem Echo %%i %%j %%k %%l %%m %%n %%o %%p %%q %%o

echo GroupName = %%k %%l
echo NodeName = %%m
echo ResourceName = Cluster IP Address
echo ResourceStatus = Online
echo.
)

Goto :EOF

:functionArray
set /a strArrayNumber=%strArrayNumber% + 1
set strArrayName.%strArrayNumber%=%strArrayValue%

Goto :EOF


Report •

#3
July 28, 2010 at 00:17:38
I just notice when i post the messages to the board, it squashes the sample removing the white space.
I've replace the whitespace with underscores of the fist line as an example so you can see where the 3 distinct columns are

Cluster IP Address___Cluster Group_______ISRMIS21________Online


Report •
Related Solutions


Ask Question