rlburris
asked on
I Need Unix Shell Script to calculate Celsius to Fahrenhiet.
(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!
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!
homework question ?
ASKER
Nope... I support a Unix system that I need to monitor the system temperature.
echo $(echo "scale=2; $cel*1.8+32" | bc)
$cel is your temp in celcius
$cel is your temp in celcius
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
youcan chop off two lines of the perl script
#!/usr/local/bin/perl -n
printf "%.2f\n", (($_ * 1.8) + 32);
/abhiijt/
#!/usr/local/bin/perl -n
printf "%.2f\n", (($_ * 1.8) + 32);
/abhiijt/
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)
#!/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)
ASKER
SunnyCoder:
I receive a syntax error, '(' unexpected.
Also what does "scale=2" do?
I receive a syntax error, '(' unexpected.
Also what does "scale=2" do?
ASKER
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!
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
avizit,
Every time I run this I get a value of 32.00?
Every time I run this I get a value of 32.00?
ASKER
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!
#!/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!
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/
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/
ASKER
Avizit,
I got it to work... Thanks for your help!
I got it to work... Thanks for your help!