Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9066827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:48:16+00:00 2026-06-16T16:48:16+00:00

The purpose of my code is To read two values from two separate files.

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:48:17+00:00Added an answer on June 16, 2026 at 4:48 pm

    What shell are you using? I’m assuming just plain old ‘sh’ or ‘bash’.

    If so, look at line 33 where you have:

    if($Threshhold<0) then

    Switch that to:

    if [ $Threshhold -lt 0 ]; then

    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’):

    # Example test.sh file
    !/bin/bash
    
    while read line;
    do
    echo "$line";
    AllOn=$line
    done < Output.log
    
    while read line;
    do
    echo "$line";
    AllOff=$line
    done < BaseFile.log
    
    #Threshhold Value
    Threshold=`echo "$AllOn - $AllOff" | bc`;
    echo "Threshold is $Threshold"
    if [ `echo "$Threshold < 0"|bc` ]; then
      # snips off the '-' sign which is what you were trying to do it looks
      Threshold=${Threshold:1}
    fi
    echo $Threshold
    Result=result.txt
    echo "\nThreshold is $Threshold" >> $Result
    

    Then some data files, first Output.log:

    # Output.log
    1.2
    

    Then BaseFile.log:

    # BaseFile.log
    1.3
    

    Example output from the above:

    ./test.sh
    1.2
    1.3
    Threshold is -.1
    .1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Purpose: Create a program that takes two separate files, opens and reads them, assigns
I have two programs working together to write and read data from a file.
The purpose of this code is to pull upgrade.zip from a central server, extract
Suppose i have the code snippet as follows : ( clarification purpose/not well formed
The purpose of the code is to find a portion of a string (from
This code comes from K&R. I have read it several times, but it still
I have to call ping from c++ code.I'd like to easily read the output
I've got following (simplified for example purpose) code and it works: void log(const string
Quick question, What have I done wrong here. The purpose of this code is
What is the purpose of these java.lang.annotation imports in this code? Why are they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.