- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: A quick on scripting ? Multiple addition. help...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2006 11:55 PM
03-16-2006 11:55 PM
datafile.txt
#---------------
1.78
9.00
8.80
128.82
7.13
0.71
19.49
5.34
4.61
7.94
3.23
47.82
190.03
6.72
16.28
0.06
16.45
0.41
1.17
5.82
5:38
41.53
---------------
How to use bc or any other utility , to add this values altogether.
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2006 12:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2006 12:17 AM
03-17-2006 12:17 AM
Re: A quick on scripting ? Multiple addition. help!
file=$1
let start=0
cat $file|while read line
do
if [ "$start" = "0" ]
then
start=$line
else
start1=$(echo $start + $line |bc)
echo $start + $line = $start1
start=$start1
fi
done
~
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2006 12:38 AM
03-17-2006 12:38 AM
Re: A quick on scripting ? Multiple addition. help!
It works great.
# cat datafile.txt | awk '{sum=sum+$1} END {print sum}'
528.14
---------------
Thanks all who replied.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2006 12:53 AM
03-17-2006 12:53 AM
Re: A quick on scripting ? Multiple addition. help!
cat datafile.txt|xargs echo|sed "s/ / + /g"|bc
live free or die
harry d brown jr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2006 03:28 AM
03-17-2006 03:28 AM
Re: A quick on scripting ? Multiple addition. help!
It's not necessary to use cat:
awk '{t+=$1};END {printf "%10d\n", t}' datafile.txt
I also suggest to use printf instead of print to print formatted result in a readable way.
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2006 10:10 PM
03-19-2006 10:10 PM
Re: A quick on scripting ? Multiple addition. help!
good command thanks, but its not giving the decimal values.
# awk '{t+=$1};END {printf "%10d\n", t}' datafile.txt
528
#
-------------
The actual result is 528.14
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2006 10:16 PM
03-19-2006 10:16 PM
Re: A quick on scripting ? Multiple addition. help!
'printf' has many formatting options. To sum the contents of your file and retain 2-decimal places:
# awk '{t+=$1};END {printf "%10.2f\n", t}' file
See the manpages for 'printf' for more information.
Regards!
...JRF...