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:

#!/bin/bash
dumpraw=bavan1                                      //file1
dumpafterpack=bavan2                              //file2
index1=0
index2=0
cat $dumpraw > $dumpraw.tmp                 // just make temp file of file 1
cat $dumpafterpack > $dumpafterpack.tmp  // temp file of file2

while read line1 ; do              
   MYARRAY1[$index1]="$line1"
    index1=$(($index1+1))
done < $dumpraw.tmp
rm -rf $dumpraw.tmp

while read line2 ; do
   MYARRAY2[$index2]="$line2"
    index2=$(($index2+1))
done < $dumpafterpack.tmp
rm -rf $dumpafterpack.tmp

v3=0
v3=`wc -c bavan1 | cut -d' ' -f1`
v4=`wc -c bavan2 | cut -d' ' -f1`

i=1
if [ $v3 -ne $v4 ] ;  then 
   echo "Error: You are comparing two files which dont have equal number of characters"
   exit 1
else
   while [ $i -lt $v3 ];
       do
		a1=`echo ${MYARRAY1[*]} | cut -c$i`  //this line runs forever,why?
        	a2=`echo ${MYARRAY2[*]} | cut -c$i` //this line runs forever,why?
       			if [  $a1 != $a2 ]
             			then if [ $a1 != "x" ]
                  			then 
                      			echo " $a1 : $a2 "
                  	             fi
       		        fi
       			 
       		let i++
     done
fi

I guess there may be a buffer overflow or something? Anybody have a simple code block?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.