The purpose of my code is
- To read two values from two separate files. [Working perfectly well]
- To convert them into decimal values. [Working fine]
- Find their differences. [Working fine]
- To make the difference positive if it is a negative value. [Not Working, it’s not checking the condition.]
Here is my code. Its coded in Ubuntu 11.04.
...
while read line;
do
echo -e "$line";
AllOn=$line
done<Output.log
gcc -Wall -o0 Test.c -o output
time -f "%e" -o BaseFile.log ./output
while read line;
do
echo -e "$line";
AllOff=$line
done<BaseFile.log
#Threshold Value
Threshold=`echo "$AllOff - $AllOn" | bc`;
echo "Threshold is $Threshold"
if [ `echo "$Threshold < 0.00"|bc` ]; then
Threshold=`echo "$Threshold * -1" | bc`;
fi
echo "\nThreshold is $Threshold" >> $Result
Now, irrespective of the value, the if clause is getting executed. I think, my if condition is not being checked and that it would be the reason for the following output.
Base Time is 2.94 All Techniques Off = 3.09 Threshold is .15 Base Time is 3.07 All Techniques Off = 2.96 Threshold is -.11
UPDATE: This question is not answered completely yet and if any one could suggest me a way to achive my 4th objective of finding the difference between the values, it would be really helpful for me. Thank you.
What shell are you using? I’m assuming just plain old ‘sh’ or ‘bash’.
If so, look at line 33 where you have:
Switch that to:
You might have other issues, I haven’t looked through the code closely to check for them.
To further expand, I knocked up test script and data (please note I changed ‘Threshhold’ to ‘Threshold’):
Then some data files, first Output.log:
Then BaseFile.log:
Example output from the above: