Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reformat report file to move columns to rows for each block of data

Status
Not open for further replies.

axonm

Technical User
Oct 11, 2001
3
GB
Hi,

I have a report file from DB2/UDB for AIX. The report file looks like this:
db2 "list tablespaces show detail"

Tablespaces for Current Database

Tablespace ID = 0
Name = SYSCATSPACE
Type = System managed space
Contents = Any data
State = 0x0000

and so on, each tablespace ID delimits the block in the report and each block contains 16 or 17 lines.
I want to take the value after the = symbol and produce a list like this

0 SYSCATSPACE System managed space any data 0x0000

Following on from this I will need to exclude some of text string fields as the real requirement is to obtain data about the allocated, used and free space.

Thanks
 
This should get you started.
Code:
BEGIN{FS="="}
/Tablespace ID/ {
  for (i=1;i<ix;i++) printf a[i]
  print &quot;&quot;
  ix = 1
  }
(ix>0) {a[ix++]=$2}
END{
  for (i=1;i<ix;i++) printf a[i]
  print &quot;&quot;
}
Hope this helps. CaKiwi
 
Thank you CaKiwi for your prompt response unfortunately due to my inexperience with AWK (or ignorance!) I do not really understand how the above should fit in a shell script or what it is doing. I have managed to strip out the unwanted data from the source file so that I have only the data I want in a single column e.g.
0
SYSCATSPACE
System managed space
5235
5235
5235
Not applicable
Not applicable
4096
32
32
1
2001-02-03-06.24.53.000000

I just need now to turn this column of data into a row and then change the next set of columns into a row.

I appreciate your input on this as I am sure you have better things to do than help novice AWKers.
 
Create a file containing my awk script and enter

awk -f awk-script your-file > changed file

Run it on your original file, it would be more difficult to do it for the file you modified because with Tablespace ID removed you don't know where to start each new line.

Hope this helps. CaKiwi
 
Thanks CaKiwi for your input that appears to be working fine now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top