The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 03-18-2009
luna_soleil luna_soleil is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 33
Comparing 2 words

Hi

I have assigned list of arrays as below:
rtab[1]="TAB1 Y"
rtab[2]="TAB2 Y"
rtab[3]="TAB3 Y"
rtab[4]="TAB4 Y"

And I have a text file comp.txt that contains
>vi comp.txt
TAB1 Y
TAB2 Y
TAB3 Y
TAB4 Y

I want to compare the content of the array with the content in comp.tx.. so I have written the code as below :

i=0
while read ttab
do
arr[$((i=i+1))]=$ttab
if [ $ttab = ${rtab[i]} ]
then
echo "${rtab[i]} -> status is Y [PASS]"
else
echo "${rtab[i]} -> status is N [FAIL]"
fi
done < comp.txt

But unfortunately I've been getting output ..status is N [FAIL] everytime i run this script.
Is this because the script can't compare 2 words TAB Y ("TAB2 Y" compare with "TAB2 Y" is not permitted, "TAB" compare with "TAB" is OK)?
If yes, how do I rectify this?

Thank u very much

Last edited by luna_soleil; 03-18-2009 at 02:06 PM..