- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Adding a column of numbers in a file
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-25-2007 10:57 PM
03-25-2007 10:57 PM
I'm looking to total up all the numbers in a file as part of a shell script.
sample file is like below, now i'll have hundreds of numbers
68
8
2
2
Thanks
Paddy
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2007 11:01 PM
03-25-2007 11:01 PM
Solutionyou don't mention a preference for solution, so here is one in awk:
awk 'BEGIN {total=0;} {total=total+$1;} END {print total,"\n";}' data.lis
Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2007 11:08 PM
03-25-2007 11:08 PM
Re: Adding a column of numbers in a file
As part of the same script all these numbers are generated into a file. I want to total the number in them and if it's above a certain treshold it will mail me.
So will i cat the file with all numbers in it and pipe it to your awk command you supplied?
Paddy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2007 11:13 PM
03-25-2007 11:13 PM
Re: Adding a column of numbers in a file
Thanks for that
Paddy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2007 11:15 PM
03-25-2007 11:15 PM
Re: Adding a column of numbers in a file
my test was:
$ cat a.lis
1.1
2.5
3
4
$ level=`awk 'BEGIN {total=0;} {total=total+$1;} END {print total,"\n";}' a.lis`
$ echo $level
10.6
$
Just to check that it worked with float as well.
In your case you can use the $level bit to then decide whether to mail. Something like:
level=`awk ....
if [ $level -gt 75 ]
then
echo "Level is $level" | mailx -s "level reached" usr@aol.com
fi