Operating System - Linux
1753797 Members
7021 Online
108799 Solutions
New Discussion юеВ

Turn a report into one line per record with awk ?

 
SOLVED
Go to solution
Stuart Abramson
Trusted Contributor

Turn a report into one line per record with awk ?

I would like some awk help.

This is the output from syminq -clar -v. It produces some 15 lines for every LUN presented to this server:

Device Physical Name : /dev/rdsk/c101t5d3
Device Serial ID : Ch2 CONT

Vendor ID : DGC
Product ID : CX700WDR5
Product Revision : HP03

Peripheral Device Type : Direct Access

Controller Number : 65
Target ID : 5
Logical Unit Number : 3

Capacity (in KB) : 8838720

Clariion ID : APM00052802175
Device Clariion Name : 0117

Device State : ASSIGNED
Device WWN : 60:06:01:60:90:84:15:00:5C:B1:65:C1:AC:10:DA:11

Powerpath Device Type : CHILD

VxVM DMP Device Type : N/A



Device Physical Name : /dev/rdsk/c101t5d4
Device Serial ID : Ch2 CONT

Vendor ID : DGC
Product ID : CX700WDR5
Product Revision : HP03

Peripheral Device Type : Direct Access

Controller Number : 65
Target ID : 5
Logical Unit Number : 4

Capacity (in KB) : 70709760

Clariion ID : APM00052802175
Device Clariion Name : 0116

Device State : ASSIGNED
Device WWN : 60:06:01:60:90:84:15:00:FC:B4:A8:13:AC:10:DA:11

Powerpath Device Type : CHILD

VxVM DMP Device Type : N/A

I would like to turn this into one line per LUN, like this:

Dev Type GB Array LuN
c101t5d3 CX700WDR5 7079760 APM..2175 0116

But I cant' figure out how to do it.

I tried:

awk '{RS="Device Physical Name"; print $3, $9...}'

but it's not working..
5 REPLIES 5
RAC_1
Honored Contributor

Re: Turn a report into one line per record with awk ?

syminq -v -clar | egrep "Device Physical Name|Product ID|Capacity \(in KB\)|Clariion ID|Device Clariion Name" | tr "\n" "\c"

There is no substitute to HARDWORK
Marlou Everson
Trusted Contributor
Solution

Re: Turn a report into one line per record with awk ?

Save the desired info in a variable and print it out at the end. For example,

awk '{/Device Phy/ {ctd=$5;next}
/Product ID/ {prodid=$4;next}
/Capacity/ {kb=$5;next}
/VxVM/ {print ctd, prodid, kb/1000}'

I'm guessing the fields.

Marlou
Hein van den Heuvel
Honored Contributor

Re: Turn a report into one line per record with awk ?


Marlou outlines the classic and recommended solution, specially if you are goinf to be selecting specific fields, adn possibly re-ordering the output.

Now if the problem is simple "I would like to turn this into one line per LUN" then the answer would be:

awk -F" : " '{if (NF>1){ line = line " " $2}}/^VxVM/{print line; line = ""}' x


. make " : " the field seperator.
. if more than 1 field in the input then add field 2 to variable 'line'.
. if input starts with VxVM then print the line variable and clear it.

Hein.

Victor Fridyev
Honored Contributor

Re: Turn a report into one line per record with awk ?

Hi,

If the string with VxVM DMP Device Type is the last in the output, try this:
awk 'NF<2{next}
/VxVM DMP Device Type/ {print $NF;next}
{printf("%s ",$NF}'

HTH
Entities are not to be multiplied beyond necessity - RTFM
Stuart Abramson
Trusted Contributor

Re: Turn a report into one line per record with awk ?

all good answers. Thanks.