943,779 Members | Top Members by Rank

Ad:
Jan 30th, 2008
0

Seeks help to compare strings stored in arrays

Expand Post »
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. }
Reputation Points: 16
Solved Threads: 11
Junior Poster in Training
lookof2day is offline Offline
83 posts
since Aug 2007
Jan 30th, 2008
0

Re: Seeks help to compare strings stored in arrays

This is ugly but it works!

Shell Scripting Syntax (Toggle Plain Text)
  1. if [ "$NAME*" == "$HTML_NAME*" ]; then
Reputation Points: 16
Solved Threads: 11
Junior Poster in Training
lookof2day is offline Offline
83 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Replacing characters in a foldername
Next Thread in Shell Scripting Forum Timeline: cronjob problem in the script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC