System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

convert a column to row output?

SOLVED
Go to solution
Manuel Contreras
Regular Advisor

convert a column to row output?

Getting tired of cut-and-paste...so I thought I would post a question.

how do I change this column output to a single row?

from this:

# vgdisplay -v /dev/vgeva05 | grep dsk | awk '{print $3}'
/dev/dsk/c6t0d5
/dev/dsk/c11t0d5
/dev/dsk/c15t0d5
/dev/dsk/c18t0d5
/dev/dsk/c7t0d5
/dev/dsk/c10t0d5
/dev/dsk/c14t0d5
/dev/dsk/c19t0d5


to this:
/dev/dsk/c6t0d5 /dev/dsk/c11t0d5 /dev/dsk/c15t0d5 /dev/dsk/c18t0d5 /dev/dsk/c7t0d5 /dev/dsk/c10t0d5 /dev/dsk/c14t0d5 /dev/dsk/c19t0d5



any assistance would be appreciated...

manny
4 REPLIES
Hein van den Heuvel
Honored Contributor
Solution

Re: convert a column to row output?


Personally I would ask the question in the HPUX or a linux forum, not in an OpenVMS forum.

Anyway... I'd use something like...


vgdisplay -v /dev/vgeva05 | awk 'END {print line} /dsk/ { line = line " " $0 }'

Notice how this also cuts out the middle-man (grep )

hth,
Hein

Manuel Contreras
Regular Advisor

Re: convert a column to row output?

Thanks Hein,
sorry about the openVMS, didn't catch it when posting...need coffee :)

tried your command, but output was impacted by "Alternate Link, etc...):
$ vgdisplay -v /dev/vgeva05 | awk 'END {print line} /dsk/ { line = line " " $0 }'
PV Name /dev/dsk/c6t0d5 PV Name /dev/dsk/c11t0d5 Alternate Link PV Name /dev/dsk/c15t0d5 Alternate Link PV Name /dev/dsk/c18t0d5 Alternate Link PV Name /dev/dsk/c7t0d5 Alternate Link PV Name /dev/dsk/c10t0d5 Alternate Link PV Name /dev/dsk/c14t0d5 Alternate Link PV Name /dev/dsk/c19t0d5 Alternate Link


from your suggestion, the following work :)

$ vgdisplay -v /dev/vgeva05 | grep dsk | awk '{print $3}' | awk 'END {print line} { line = line " " $0 }'
/dev/dsk/c6t0d5 /dev/dsk/c11t0d5 /dev/dsk/c15t0d5 /dev/dsk/c18t0d5 /dev/dsk/c7t0d5 /dev/dsk/c10t0d5 /dev/dsk/c14t0d5 /dev/dsk/c19t0d5

or

$ vgdisplay -v /dev/vgeva05 | awk '{print $3}' | awk 'END {print line} /dsk/ { line = line " " $0 }'
/dev/dsk/c6t0d5 /dev/dsk/c11t0d5 /dev/dsk/c15t0d5 /dev/dsk/c18t0d5 /dev/dsk/c7t0d5 /dev/dsk/c10t0d5 /dev/dsk/c14t0d5 /dev/dsk/c19t0d5


thank you,

manny
Manuel Contreras
Regular Advisor

Re: convert a column to row output?

soooo much easier and less susceptible to errors :)
Hein van den Heuvel
Honored Contributor

Re: convert a column to row output?

You added more middle men!

I had a typo in my answer, selecting the whole line ($0) instead of the 3rd field:

Should have been:

vgdisplay -v /dev/vgeva05 | awk 'END {print line} /dsk/ { line = line " " $3 }'

Glad you are happy,

Hein.