- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: using awk to calculate
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
Discussions
Discussions
Forums
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
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
тАО09-18-2006 03:59 AM
тАО09-18-2006 03:59 AM
I am attempting to use awk to calculate some numbers. I have put the figures into a file from the df command:
# cat mydf.out
2424
4246432
32434672
323
5432521
43433
etc etc
I want to add them all together with the total being displayed at the end - have attempted with no luck:
cat mydf.out |awk 'BEGIN {tot=0} {tot=+$1} END {print tot}'
how can I do this using awk please?
many thnaks
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2006 04:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2006 04:11 AM
тАО09-18-2006 04:11 AM
Re: using awk to calculate
#!/usr/bin/sh
#
BDFMEGS=/usr/local/bin/bdfmegs
if [ ! -x $BDFMEGS ]
then
echo "ERROR: $BDFMEGS does not exist!"
exit 1
fi
SUM=0
# Cut out the first line from output
$BDFMEGS | sed '1,1d' | grep -v : | while read a b c d e f
do
SUM=`expr $SUM + $c`
#echo $SUM
done
echo "Total Space Used (MB) = $SUM"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2006 04:24 AM
тАО09-18-2006 04:24 AM
Re: using awk to calculate
Awk was very non-judgemental and just did what it was told. :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2006 06:09 AM
тАО09-18-2006 06:09 AM
Re: using awk to calculate
cat mydf.out |awk 'BEGIN {tot=0} {tot=tot+$1} END {print tot}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2006 06:20 AM
тАО09-18-2006 06:20 AM
Re: using awk to calculate
awk '{tot+=$1}END{print tot}' mydf.out
- Tags:
- evil cat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2006 07:09 PM
тАО09-18-2006 07:09 PM
Re: using awk to calculate
10 out of 10 for me for the useles cat award!!
It's a bad habit I am trying to break.
Chris.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2006 07:10 PM
тАО09-18-2006 07:10 PM