Showing results for 
Search instead for 
Do you mean 

array help

Honored Contributor Honored Contributor

array help

Hi Everyone

Need a little help with comparing information in arrays.

I have the below example from a script

check=0
hostnum=0
offset=10

for hosts in ${host[@]}
do swlist @ $hosts | egrep 'MC ?\/ ?Service ?Guard' | while read num ver desc
do
((index=hostnum*offset+check ))
colnum[$index]=$num
colver[$index]=$ver
coldesc[$index]=$desc
((check = check + 1 ))

I'm trying to create a seperate array for each column, then compare per column to ensure they are equal. The output looks like below. How can I now compare each column when I don't know how many hosts I have or number of columns ?

below is the make up of each array element

colnum[0]=B3935DA
colver[0]=A.11.14
coldesc[0]=MC / Service Guard
colnum[1]=PHSS_29915
colver[1]=1.0
coldesc[1]=MC/ServiceGuard and SG-OPS Edition A.11.14
colnum[12]=B3935DA
colver[12]=A.11.14
coldesc[12]=MC / Service Guard
colnum[13]=PHSS_29915
colver[13]=1.0
coldesc[13]=MC/ServiceGuard and SG-OPS Edition A.11.14

Hmmm, typing this out I can see that it's getting a bit messy. I only want to compare for eg the output of each line against it's adjacent line

so

line 1 column 1 against (if there is one) line 1 column 1 of the output for the next host etc etc

uuurrrggghhh

Thanks in advance

Steven


take your time and think things through
2 REPLIES
Honored Contributor Honored Contributor

Re: array help

I finish now for the day so will pick up any responses when I get up this afternoon

thanks

Steven
take your time and think things through
Highlighted
Honored Contributor Honored Contributor

Re: array help

The sh-posix's array is a bit limited.
For nested data structure I'd rather suggest Perl, especially with its magic autivivification.

Without delving into your code you can quite easily determine how many elements your host aray got assigned.
Simply evaluate ${#host[*]}
But I bet you knew that.
Madness, thy name is system administration