For loop not giving expected output

#cat /tmp/input
old_array   old_dev  new_dev  new_array
0577    008AB   01744   0125
0577    008AC   01745   0125
0577    008AD   005C8   0125
0577    008AE   005C9   0125
0577    008AF   005CA   0125
0577    008B0   005CB   0125
0577    008B1   005CC   0125
cat test.sh
#!/bin/ksh
#set -x
for i in $(lspv |grep hdisk | awk '{print $1}')
do
        for j in $(cat /tmp/input | grep hdisk | awk '{print $3}')
        do
	        k=`lscfg -vl $i |grep $j`
        	print $i $k
        done
done

The script outputs all of the available disks multiple times but not the disk number and its corresponding new_dev value from /tmp/input file that I'm trying to get.
Note: One thing I just noticed is that the 'new_dev' value in 3rd column from /tmp/input file has 5 digits whereas the lscfg output in the script for 'k' variable has only 4 digit i.e., there is no leading '0', is it possible to add a leading zero to the value that goes into 'k'

Thanks!

Showing us an input file and non-working code without a clear explanation of what output you are trying to produce does't help a lot.

What does the lspv utility do? What output does it produce?

What does the lscfg utility do when invoked with the l and v flags and given one operand?

What output are you hoping to produce from the sample input you provided?

1 Like

My bad...I didn't realize about lspv and lscfg outputs.

Here is the sample output of lspv and lscfg for reference

# lspv | awk '{print $1}'
hdisk0
hdisk1
hdisk2
hdisk3
hdisk4
hdisk5
hdisk6
hdisk7


# lscfg -vl hdisk0 |grep LIC
        LIC Node VPD................1744

-->This value is same new_dev value from /tmp/input file

I'm trying to get hdisk number from lspv and its corresponding LIC value from lscfg based on /tmp/input file printed out.

I can't see a relation between the outputs of the two commands given in post#3 connected by the /tmp/input contents.
Why don't you take a step back, and rephrase your request including ALL data available (and necessary to deal with it)?

1 Like

Thanks for your suggestion to take a step back,
here is the working code,

#!/bin/ksh
for i in $(lspv |grep hdisk | awk '{print $1}')
do
    LIC=$(lscfg -vl $i |grep LIC | cut -d\. -f17)
    DISK=$(cat /tmp/input | awk '{print $3}' | grep $LIC)
    [[ -n $DISK ]] && echo "$i:$LIC"
done