Solved

I Need Unix Shell Script to calculate Celsius to Fahrenhiet.

Posted on 2004-04-26
13
718 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 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