extra space issue with awk

for diskname in $(lspv |awk '{print $1}')
do
lquerypv -h /dev/|awk '/'$diskname'/ { print ; exit }'
done

No output is returning from the loop.
I think awk put an extra space to the command - lquerypv -h /dev/
so that the command is executed as i.e. lquerypv -h /dev/ hdisk230 with a space between /dev/ and hdisk230.

Please advise how to remove an extra space in this case if my guess is correct.

Thank you

Do:

lspv |awk '{print "="$1"="}'

so you don't have to guess :wink:

lspv |awk '{print "="$1"="}'

returns the outputs with =

=hdisk0=
=hdisk1=
=hdisk113=
...
 lspv |awk '{print "/dev/"$1}' 

gives me like this:

/dev/hdisk0
/dev/hdisk1
/dev/hdisk113
...

It looks good so far, but if I put in

for diskname in $(lspv |awk '{print "/dev/"$1}')
do
lquerypv -h |awk '/'$diskname'/ { print ; exit }'
done

I am getting errors:

 Syntax Error The source line is 1.
 The error context is
                //dev/hdisk0/ >>>  { <<< 
 awk: 0602-500 Quitting The source line is 1.
 Syntax Error The source line is 1.
 The error context is
                //dev/hdisk1/ >>>  { <<< 
 awk: 0602-500 Quitting The source line is 1.
 Syntax Error The source line is 1.
 The error context is
                //dev/hdisk113/ >>>  { <<< 
 awk: 0602-500 Quitting The source line is 1.

Please advise.

Thank you so much

Try:

for diskname in $(lspv |awk '{print $1}')
do
lquerypv -h /dev/|awk -vx=$diskname '$0~x{ print ; exit }'
done

I tried:

for diskname in $(lspv |awk '{print $1}')
do
lquerypv -h /dev/|awk -vx=$diskname '$0~x{ print ; exit }'
done

but, no output is returned still.
Please advise.

Are you sure this command is giving proper output? (containing disk names?):

lquerypv -h /dev/

The command has to be:

lquerypv -h /dev/hdisk# 

// please note no space on

/dev/hdisk#

hdisk# comes from

 '/'$diskname'/ { print ; exit }'

It looks to me that i.e.

 lquerypv -h /dev/ hdisk0 

(please note a space) is executed.

Please advise.

If the command has to be:

lquerypv -h /dev/hdisk#

then your whole syntax is wrong. It should be:

for diskname in $(lspv |awk '{print $1}')
do
lquerypv -h /dev/$diskname
done