- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: rounding up in awk/shell
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
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
тАО10-08-2002 01:54 AM
тАО10-08-2002 01:54 AM
our usual memory.sh script which uses adb and the kernel to display the system memory total works fine on 10.20 and 11.0 but on 11.11 it computes to an integer instead of a round number, eg;
echo "phys_mem_pages/D" | adb /stand/vmunix /dev/kmem|grep phys|tail -1|awk '{printf $2/256}'
On our server with 768Mb of RAM shows 767.992
My question is how can we round this up in awk (should display 768) or using prinf. Ive tried but cant figure it. I know this can be done the long way in a shell script or probably in perl, definitely in C using round, but Im after a 1 liner using awk and/or printf to do it - and so that it works on servers with different memory sizes.
Thanks,
Stefan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2002 02:00 AM
тАО10-08-2002 02:00 AM
Re: rounding up in awk/shell
echo "767.99" | awk '{printf("%d\n",$1 + 0.5);}'
768
echo "767.49" | awk '{printf("%d\n",$1 + 0.5);}'
767
echo "767.51" | awk '{printf("%d\n",$1 + 0.5);}'
768
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2002 02:03 AM
тАО10-08-2002 02:03 AM
Re: rounding up in awk/shell
echo "phys_mem_pages/D" | adb /stand/vmunix /dev/kmem|tail -1|awk '{printf "%d",$2/256+.5}'
BTW, I dropped the grep... it failed on my 11.11 box.
Regards...
Dietmar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2002 02:12 AM
тАО10-08-2002 02:12 AM
Re: rounding up in awk/shell
Hey, come on guys, no simply adding 1 or .5 or whatever to it. I want to round up. Must be able to round with awk, or nawk, or bc or dc or bs ??? anyone ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2002 02:16 AM
тАО10-08-2002 02:16 AM
Re: rounding up in awk/shell
What's the differnence between rounding up X and rounding down (X+.5)? Why should a designer include such a redundant functionality? :)
Regards...
Dietmar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2002 02:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2002 02:23 AM
тАО10-08-2002 02:23 AM
Re: rounding up in awk/shell
sorry, im purely being pedandtic. I want to round up or down using awk or a shell script in a one liner if possible. You can do in C, probably in perl, but not in a simple shell script/command ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2002 02:29 AM
тАО10-08-2002 02:29 AM
Re: rounding up in awk/shell
That did it! you dont need perl - your printf function is rounding perfectly (>.5 = up, < .5 round down). This now works;
echo "phys_mem_pages/D" | adb /stand/vmunix /dev/kmem|grep phys|tail -1|awk '{printf "%.0f MB\n",$2/256}'
Thanks!
Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2002 02:40 AM
тАО10-08-2002 02:40 AM
Re: rounding up in awk/shell
Well , I build it
You may like it or Not, just try to help
echo $1 | awk '
function round(aa) {
return int( aa + 0.5 )
}
{
printf("%d\n",round($1));
}'
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2002 03:07 AM
тАО10-08-2002 03:07 AM
Re: rounding up in awk/shell
Thankyou for asking. I've just been accepting the answer as is and rounding up myself. This is much better.
Eternally grateful,
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2002 05:44 AM
тАО10-08-2002 05:44 AM
Re: rounding up in awk/shell
echo "767.992" | awk '{printf("%5.0f\n",$0)}'
To round down using awk:
echo "767.992" | awk '{printf("%d\n",$0)}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2002 05:53 AM
тАО10-08-2002 05:53 AM
Re: rounding up in awk/shell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2002 11:14 AM
тАО12-04-2002 11:14 AM
Re: rounding up in awk/shell
I had the same question and found my answer(s) right here using search. Thanks, Stephen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2002 11:16 AM
тАО12-04-2002 11:16 AM
Re: rounding up in awk/shell
;^)
Pete
Pete