Operating System - HP-UX
1825792 Members
2742 Online
109687 Solutions
New Discussion

Re: print fields in a row

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

print fields in a row

Hi all,

I am trying to print all occurances of a string that appear in a row so here is the file:

vpath12 12928727 = hdisk36 (Avail ) hdisk124 (Avail ) hdisk45 (Avail ) hdisk126 (Avail )
vpath23 40B28727 = hdisk42 (Avail ) hdisk136 (Avail ) hdisk59 (Avail ) hdisk138 (Avail )
vpath26 43128727 = hdisk50 (Avail ) hdisk70 (Avail ) hdisk143 (Avail ) hdisk149 (Avail )
vpath40 04D29942 = hdisk95 (Avail ) hdisk164 (Avail ) hdisk75 (Avail ) hdisk83 (Avail )


I would like the output to read

hdiskx hdiskx hdiskx hdiskx vpathx
and so on

thanks

hello
4 REPLIES 4
lawrenzo_1
Super Advisor

Re: print fields in a row

I suppose what I am tryingto achieve is that I want to use awk to check each field in the row and when the pattern is matched then it is printed:

awk '/vpath/ { vpath = $1};{for (i=1;i<=NF;++i)} {if ( i ~ hdisk ) {hdisk = i}} {print hdisk,vpath }'

16 vpath12
16 vpath23
16 vpath26
16 vpath40


not quite what I want ....

hello
James R. Ferguson
Acclaimed Contributor
Solution

Re: print fields in a row

Hi Chris:

You're close:

# awk '/vpath/ {vpath=$1};{for (i=1;i<=NF;++i) {if ($i~/hdisk/) {PATH=PATH" "$i}};{print PATH,vpath}}' file

Regards!

...JRF...
Peter Nikitka
Honored Contributor

Re: print fields in a row

Hi,

try this:

awk '/^vpath/ {j=0; for(i=4;i
mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
lawrenzo_1
Super Advisor

Re: print fields in a row

ok thanks guys - both work for me!

Chris.
hello