Solved

I Need Unix Shell Script to calculate Celsius to Fahrenhiet.

Posted on 2004-04-26
13
716 Views
Last Modified: 2013-12-26
(in case you don't know)
Formula = Celsius degrees * 1.8 + 32 = Fahrenhiet

For this script, lets say Celsius degrees = 27.12

Let me know if this is easier done in Perl.

Thanks!
0
Comment
Question by:rlburris
  • 6
  • 3
  • 2
  • +1
13 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10925793
homework question ?
0
 

Author Comment

by:rlburris
ID: 10925868
Nope... I support a Unix system that I need to monitor the system temperature.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10925980
echo $(echo "scale=2; $cel*1.8+32" | bc)

$cel is your temp in celcius
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 3

Assisted Solution

by:PerlKing
PerlKing earned 200 total points
ID: 10926757
If you would like to have a perl script to do this, create a file cel2far.pl and put the following code in it:

#!/usr/local/bin/perl

while(<>) {
   printf "%.2f\n", (($_ * 1.8) + 32);
}

Now run it as
./cel2far.pl

You can keep entering the value in Farenhiet and it would keep printing the values in Celsius
0
 
LVL 11

Expert Comment

by:avizit
ID: 10926881
youcan chop off two lines of the perl script

#!/usr/local/bin/perl -n
printf "%.2f\n", (($_ * 1.8) + 32);

/abhiijt/

0
 
LVL 3

Expert Comment

by:PerlKing
ID: 10927002
If you want your script to take the Celsius value as a command line argument and print it.

#!/usr/local/bin/perl
printf "%.2f\n", (($ARGV[0] * 1.8) + 32);

You can now invoke you script like this:
./cel2far.pl 100
212.00 (this is the output)
0
 

Author Comment

by:rlburris
ID: 10929867
SunnyCoder:

I receive a syntax error, '(' unexpected.

Also what does "scale=2" do?
0
 

Author Comment

by:rlburris
ID: 10929894
PerlKing,

I need to have the Celsius value as a input file and the output needs to be stored in a output file. Can you show me what the Perl script would look like?

Thanks!
0
 
LVL 11

Accepted Solution

by:
avizit earned 300 total points
ID: 10929947
You can run

#!/usr/local/bin/perl -n
printf "%.2f\n", (($_ * 1.8) + 32);


as

./script.pl  infile > outfile


/abhijit/  
0
 

Author Comment

by:rlburris
ID: 10930252
avizit,
       Every time I run this I get a value of 32.00?
0
 

Author Comment

by:rlburris
ID: 10930322
Working solution:

#!/opt/bin/perl
while(<>) {
   printf "%.2f\n", (($_ * 1.8) + 32);
}

Now run it as
./cel2far.pl input > output

Thanks for your help!

I will split points!
0
 
LVL 11

Expert Comment

by:avizit
ID: 10930420
It works fine for me .. i tested just now


following is one transcript
> cat infile
10
11
12
-40
-14
-50
-40

> cat test.pl
#!/usr/local/bin/perl -n
printf "%.2f\n", (($_ * 1.8) + 32);

> ./test.pl infile
50.00
51.80
53.60
-40.00
6.80
-58.00
-40.00


oh btw make sure you have perl located as /usr/local/bin/perl
if not do a "which perl" and change the first line accordingly


/abhijit/
0
 

Author Comment

by:rlburris
ID: 10930451
Avizit,
       I got it to work... Thanks for your help!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ODBC Connection Logging, ADO.NET 6 69
Generic progress indicator 6 117
deburging in oracle form 12 105
windows 10 how make picture as desktop background 2 65
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question