Add up sum in file in scientific formulation in a shell script
Dear all,
the subject of the thread is my question: -Is there any easy way to sum up a file where the numbers are stored in scientific formulation? (e.g.: 5.4654654E+1 5.4654654E+0 5.4654654E-1 ) |
Quote:
Code:
5.4654654E+1 Code:
awk '{sum=sum+$1; printf "%11.7e\n", $1} Code:
5.4654654e+01 |
You can use bc see post #4 http://www.unix.com/shell-programmin...-notation.html
|
At
http://code.nasa.gov is a set of python tools called "dataProductivityToolKit" http://code.nasa.gov/project/data-productivity-toolkit/ Sourceforge page http://sourceforge.net/projects/dptoolkit/ from the readme , a list of programs Code:
p.bar Creates bar charts will do this It is some NASA code that comes in handy from time to time |
Code:
$ printf '%s\n' 5.4654654E+1 5.4654654E+0 5.4654654E-1 > infile.txt In the second version I sent the output through the shell's built-in printf to convert it to exponential notation. With the proper configuration we could certainly get bc to output it like that directly, but I'm not familiar with how to do it, and I'm too lazy right now to look it up. ;) |
Hmm, I did
Code:
echo "5.4654654E1 5.4654654E0 5.4654654E-1" | sed 's/E/*10^/g;s/ /+/g' |bc Code:
printf '%f\n' 5.4654654E+1 5.4654654E+0 5.4654654E-1 Am I wrong??? |
Hi.
The numerical utility package num-utils may be useful: Code:
#!/usr/bin/env bash Code:
% ./s1 Best wishes ... cheers, makyo |
O.K., here's another solution using my current favorite language, pure:
Code:
#!/bin/bash Code:
$ bash fd99 |
All times are GMT -5. The time now is 08:24 PM. |