Hi! Reading from a file takes lot of time?

Reply

Join Date: Sep 2008
Posts: 2
Reputation: Bavananth is an unknown quantity at this point 
Solved Threads: 0
Bavananth Bavananth is offline Offline
Newbie Poster

Hi! Reading from a file takes lot of time?

 
0
  #1
Sep 4th, 2008
Hello experts ! I'm a newbiee to this shell scripting! I try to write a "diff" kinda script which compares two text files and echos the differences. The only different is, my script doesn't care about the character "x" in the first file , being replaced with any other character in the second file. I wrote a script which was perfect(logically correct) with smaller files, takes a hell a lot of time to read 500kb files which I 'm supposed to play with for my work.

Those files contain all digital logic outputs dumped by an IP tool ( zeros(0) ,ones(1) and Don't care terms(x)). I hope now you may understand the reason why I'm trying to do this. Any help?

My code:
Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2. dumpraw=bavan1 //file1
  3. dumpafterpack=bavan2 //file2
  4. index1=0
  5. index2=0
  6. cat $dumpraw > $dumpraw.tmp // just make temp file of file 1
  7. cat $dumpafterpack > $dumpafterpack.tmp // temp file of file2
  8.  
  9. while read line1 ; do
  10. MYARRAY1[$index1]="$line1"
  11. index1=$(($index1+1))
  12. done < $dumpraw.tmp
  13. rm -rf $dumpraw.tmp
  14.  
  15. while read line2 ; do
  16. MYARRAY2[$index2]="$line2"
  17. index2=$(($index2+1))
  18. done < $dumpafterpack.tmp
  19. rm -rf $dumpafterpack.tmp
  20.  
  21. v3=0
  22. v3=`wc -c bavan1 | cut -d' ' -f1`
  23. v4=`wc -c bavan2 | cut -d' ' -f1`
  24.  
  25. i=1
  26. if [ $v3 -ne $v4 ] ; then
  27. echo "Error: You are comparing two files which dont have equal number of characters"
  28. exit 1
  29. else
  30. while [ $i -lt $v3 ];
  31. do
  32. a1=`echo ${MYARRAY1[*]} | cut -c$i` //this line runs forever,why?
  33. a2=`echo ${MYARRAY2[*]} | cut -c$i` //this line runs forever,why?
  34. if [ $a1 != $a2 ]
  35. then if [ $a1 != "x" ]
  36. then
  37. echo " $a1 : $a2 "
  38. fi
  39. fi
  40.  
  41. let i++
  42. done
  43. fi
Last edited by Narue; Sep 4th, 2008 at 1:22 pm. Reason: added code tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 2
Reputation: Bavananth is an unknown quantity at this point 
Solved Threads: 0
Bavananth Bavananth is offline Offline
Newbie Poster

Re: Hi! Reading from a file takes lot of time?

 
0
  #2
Sep 4th, 2008
I guess there may be a buffer overflow or something? Anybody have a simple code block?
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC