?
Solved

I Need Unix Shell Script to calculate Celsius to Fahrenhiet.

Posted on 2004-04-26
13
Medium Priority
?
738 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Assisted Solution

by:PerlKing
PerlKing earned 800 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 1200 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

649 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