Seeks help to compare strings stored in arrays

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2007
Posts: 81
Reputation: lookof2day is an unknown quantity at this point 
Solved Threads: 10
lookof2day lookof2day is offline Offline
Junior Poster in Training

Seeks help to compare strings stored in arrays

 
0
  #1
Jan 30th, 2008
Hi
I'm trying to compare two files names using the function given below.
The files to be compared are named as
xxx_yyy_abc_def_.rtf && xxx_yyy_abc_def_.html
The extentions and the underscores are removed from the file names and then stored in two different arrays. So the file names stored in arrays are like:

HTML_FILE_ARR[0]=abc def
FILE_ARR[0]=abc def
Their word counts are same.
But when I compare the two strings stored in different arrays, they are never equal.
Can you please help me out with it?
Shell Scripting Syntax (Toggle Plain Text)
  1. ARR_INC=0
  2. function storeFilesInArray {
  3. cd ../sharepoint_url
  4. set -a HTML_FILE_ARR
  5. for HTML_FILE in `ls $STREAM*.html`
  6. do
  7. HTML_FILE_NAME=`echo $HTML_FILE`
  8. truncateHtmlFileName
  9. HTML_FILE_ARR[$ARR_INC]="${HTML_FILE_NAME}"
  10. ARR_INC=`expr $ARR_INC + 1`
  11. done
  12.  
  13. FILE_ARR_LEN=`expr $ARR_INC - 1`
  14.  
  15. ARR_INC=0
  16. cd ../result
  17. set -a FILE_ARR
  18. for FILE in `ls $STREAM*_.rtf`
  19. do
  20. FILE_NAME=`echo $FILE`
  21. truncateFileNames
  22. FILE_ARR[$ARR_INC]="${FILE_NAME}"
  23. ARR_INC=`expr $ARR_INC + 1`
  24. done
  25.  
  26. for NAME in "${FILE_ARR[@]}"
  27. do
  28. for HTML_NAME in "${HTML_FILE_ARR[@]}"
  29. do
  30. echo $NAME "..." $HTML_NAME
  31. echo "$NAME" | wc -c
  32. echo "$HTML_NAME" | wc -c
  33. if [ "${NAME}" == "{$HTML_NAME}" ]; then
  34.  
  35. echo ${NAME} "....." ${HTML_NAME}
  36. fi
  37. done
  38. done
  39. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 81
Reputation: lookof2day is an unknown quantity at this point 
Solved Threads: 10
lookof2day lookof2day is offline Offline
Junior Poster in Training

Re: Seeks help to compare strings stored in arrays

 
0
  #2
Jan 30th, 2008
This is ugly but it works!

Shell Scripting Syntax (Toggle Plain Text)
  1. if [ "$NAME*" == "$HTML_NAME*" ]; then
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Shell Scripting Forum


Views: 1596 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC