for loop

I am trying to write a code to match words from two strings and this is the code i have written

for d in `echo boy,girl | tr ',' '\n'`
do

for i in `echo alex,rose | tr ',' '\n'`
                do
echo $d '  '  $i
done
done

Here's my output but i need only the rows boy alex & girl rose :-

Please help me on this and if both names are boy names then d would be only boy & i would be two names .

I hope you do understand how nested loops work in programming languages. Thus saying, you need to figure out a logic to make the computer understand that Alex is the name of a boy (I do recall the female characters name is Alex in the movie Irreversible).

Perhaps if you could tell us what the exact problem is, one of the forum members could help.

I am having two strings one is list of names & other is an attribute related to them i just need to match them .it's just like 1-1,2-2,3-3,4-4 if no element exists then it would be null

I am looking for a simple process to get the process completed .for now i have no idea how to do it .

#! /bin/bash

x=( "boy" "girl" )
y=( "jack" "rose" )

noX=${#x[@]}
noY=${#y[@]}

if [ $noX -gt $noY ]
then
    until=$noX
else
    until=$noY
fi

for (( i=0; i<$until; i++ ))
do
    echo "${x} ${y}"
done

Shell, perl, awk, ..

Here is using ksh/bash

cat <<EOF > $0.tmp
example :-
Attribute :- Boy,Girl,DontKnow
Names :- Alex,Rose,Yo
EOF

oifs="$IFS"

# save flds to array
while read fld deli values
do
        case "$fld"  in
                Attribute) IFS="," attr=($values) ;;
                Names) IFS="," names=($values) ;;
        esac
        IFS="$oifs"
done < $0.tmp

flds=${#attr[*]}
flds2=${#names[*]}
# max fld
((flds < flds2)) && flds=$flds2

# print out arrays
i=0
while ((i<flds))
do
        echo "${attr[$i]} ${names[$i]}"
        ((i+=1))
done

rm -f $0.tmp