change the output format

when i run the following command

db2 list tablespaces 

            Tablespaces for Current Database

 Tablespace ID                        = 0
 Name                                 = SYSCATSPACE
 State                                = 0x0000
   
 Tablespace ID                        = 1
 Name                                 = TEMPSPACE1
 State                                = 0x0000

i want it to display the output as

Tablespace ID    Name                       State
            0        SYSCATSPACE            0x0000
            1        TEMPSPACE1              0x0000

can someone guide how to use awk for this in a single command or some other process .

As a starting point, you can try something like that :

db2 list tablespaces | \
awk -F '[[:space:]]*=[[:space:]]* ' '
BEGIN            { print "Tablespace_ID Name State"; }
/^Tablespace ID/ { id    = $2 ; next }
/^Name/          { name  = $2 ; next }
/^State/         { print id, name, $2 }
'

Jean-Pierre.


SELECT DBNAME, NAME FROM SYSIBM.SYSTABLESPACE ORDER BY DBNAME,NAME

or 

SELECT TBSPACE FROM SYSIBM.SYSTABLES WHERE NAME = 'table_name' AND CREATOR='schema_name';

State of a table space cannot be predicted by using the systablespaces tables.Therefore i am going for the script .