- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Keeping floating aspect in a sum
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
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
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
02-15-2017 01:44 AM
02-15-2017 01:44 AM
Hi,
Here my code, computing a sum like this:
typeset -Z10 OCCUPANCY=0
typeset -Z10 TOTALsize=0
find /logiciel -name backup_logs -type d | while read folder
do
A=`du -ms $folder`
OCCUPANCY=`echo $A | awk -F" " '{ print $1}'`
echo "[$OCCUPANCY Mb] => $folder"
(( TOTALsize=TOTALsize+OCCUPANCY ))
done
echo "[$TOTALsize Mb] => total size"
The output si something like this:
....
[0000000.64 Mb] => /logiciel/app/oracle/diag/rdbms/iotstd0/IOTSTD0/trace/cdmp_20170111084019/backup_logs
[0000000.65 Mb] => /logiciel/app/oracle/diag/rdbms/iotstd0/IOTSTD0/trace/cdmp_20170111094523/backup_logs
[0000000.65 Mb] => /logiciel/app/oracle/diag/rdbms/iotstd0/IOTSTD0/trace/cdmp_20170111104532/backup_logs
[0000000.64 Mb] => /logiciel/app/oracle/diag/rdbms/iotstd0/IOTSTD0/trace/cdmp_20170111131544/backup_logs
[0000000.06 Mb] => /logiciel/app/oracle/diag/rdbms/sianah00/SIANAH00/trace/backup_logs
[0000000.00 Mb] => /logiciel/app/oracle/diag/tnslsnr/AIXTEST3/listener/trace/backup_logs
[0000000.00 Mb] => /logiciel/app/oracle/product/11.2.0.3/dbhome_1/log/aixtest3/client/backup_logs
[0000000.00 Mb] => /logiciel/app/oracle/product/11.2.0.3/dbhome_1/network/log/backup_logs
[0000000.42 Mb] => /logiciel/app/oracle/product/11.2.0.3/dbhome_1/rdbms/audit/backup_logs
[0000000.00 Mb] => /logiciel/app/oracle/product/11.2.0.3/dbhome_1/rdbms/log/backup_logs
[0000000.00 Mb] => /logiciel/app/oracle/product/11.2.0.4/log/aixtest3/client/backup_logs
[0000000.00 Mb] => /logiciel/app/oracle/product/11.2.0.4/network/log/backup_logs
[0000001.18 Mb] => /logiciel/app/oracle/product/11.2.0.4/rdbms/audit/backup_logs
[0000000.00 Mb] => /logiciel/app/oracle/product/12.1.0/dbhome_1/network/log/backup_logs
[0000000.79 Mb] => /logiciel/app/oracle/product/12.1.0/dbhome_1/rdbms/audit/backup_logs
[0000000.04 Mb] => /logiciel/app/oracle/product/12.1.0/dbhome_1/rdbms/log/backup_logs
[0000000017 Mb] => total size
How to keep decimal aspect for the sum ?
Any ideas ?
Kind regards,
Den.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2017 08:19 AM
02-15-2017 08:19 AM
Solution I don't do arithmetic with fractions in a shell, so I know nothing,
but ...
As I read the "man" pages, "typeset -Z" sets a field width, but says
nothing about what follows a decimal point, or even whether you have a
decimal point. For example:
mba$ (( x = 2.50 + 3.50 ))
mba$ echo $x
6
That is, "6", not "6.0", or "6.00", or "6.0000", or ...
Adding "typeset -Z" does little to change this:
mba$ typeset -Z10 a
mba$ (( a = 2.50 + 3.50 ))
mba$ echo $a
0000000006
If you want to format output, then "printf" may be closer to what you
want:
mba$ y=` printf '%010.2f' $x `
mba$ echo $y
0000006.00
No need for "typeset" this way. Less ugly, but still aligned:
mba$ y=` printf '%10.2f' $x `
mba$ echo "$y"
6.00
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2017 07:51 AM
02-17-2017 07:51 AM
Re: Keeping floating point aspect in a sum
You can either do all the work in your awk program, including the sums.
Or you can do what COBOL does, use scaled arithmetic. Which means you multiply your inputs by a power of 10 and when printing you do a divide and remainder to get the fractional parts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2017 04:08 AM
02-24-2017 04:08 AM
Re: Keeping floating point aspect in a sum
Hi,
I finally used comething like this
OCCUPANCY=$(echo "$B -$A" | bc)
Thanks folks for your help,
Kind regards,
Den.