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
тАО02-07-2002 04:20 AM
тАО02-07-2002 04:20 AM
I have written a script that reads a log file, calls 'ex' to edit what I need. Then I gather some backup stats and I need to do some division. How can I use bc in a script to devide, lets say, 400GB took 12 hours. Can I just call 'bc' and do the math?
bc
400 / 12
Or is there another way to calculate numbers?
Thanks,
Bob
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-07-2002 04:25 AM
тАО02-07-2002 04:25 AM
SolutionCheck this out:
bdf | grep -v Filesystem|grep vg02 | tr -s " " " "|cut -d" " -f 3 | sort -n | xargs echo | sed "s/ / + /g" | bc
or
echo `ls -l /tmp/va4_ioscan`"\nx x x x .65" | tr -s " " " "|cut -d" " -f 5 | xargs echo | sed "s/ / \* /g"|bc|cut -d"." -f1|sed "s/$/ \/ 512 /"|bc|sed "s:^:dd if=/t
mp/va4_ioscan of=/tmp/stewcount=:" | sh
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-07-2002 04:31 AM
тАО02-07-2002 04:31 AM
Re: bc
bc can used ie:
value=400
result=`echo "scale=2\n$value/12"|bc`
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-07-2002 04:34 AM
тАО02-07-2002 04:34 AM
Re: bc
there are some more ways to calculate:
1) the "expr" command, has the following syntax: expr nr1 operator nr2
possible operators are: addition +
subtraction -
multiplication \*
division /
for example: expr 2 \* 5
# 10
please remember, this command can only calculate integers, so expr 10 / 6 would deliver an output of 1 !
2) (( nr1 operator nr2 )), has the same functions than expr, but is done a lot of faster. Same limitations than expr, no floating point!
3) awk has also a lot of numeric builtin- functions. To use it with variable=value, you call it awk -v variable=value, then the variable is a predefined in the awk- program. The awk- command has some numeric functions which can handle floating point.
Allways stay on the bright side of life!
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-07-2002 04:46 AM
тАО02-07-2002 04:46 AM
Re: bc
If you have perl:
perl -e 'print (eval ($ARGV[0]),"\n")' 400/12
33.3333333333333
or whatever.
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-07-2002 04:53 AM
тАО02-07-2002 04:53 AM
Re: bc
If you use the "-l" (dash-el) option, you get a decimals:
[root]pbctst: echo "400 / 12" | bc -l
33.33333333333333333333
[root]pbctst:
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-07-2002 05:00 AM
тАО02-07-2002 05:00 AM
Re: bc
'bc' works quite well. For decimal numbers, include the "scale":
# X=1;Y=8;echo "scale=3\n $X/$Y"|bc
I, too, like 'awk' given its ability to format and produce output in different number bases:
# X=1;Y=8;echo "$X $Y"|awk '{printf "%.4f\n",$1/$2}'
# X=7;Y=8;echo "$X $Y"|awk '{printf "%4x\n",$1+$2}'
For simple integer arithmetic, you can use the shell 'let':
# let A=100;let B=8;let C=$A/$B;echo $C
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-07-2002 05:42 AM
тАО02-07-2002 05:42 AM
Re: bc
BC is fine.
Example
#!/usr/bin/sh
#You could use the 'two way pipe' to the program to do all your math operations,
like this:
# This starts bc with a two-way pipe
bc |&
# print -p writes to the pipe
print -p scale=4
print -p 3/4
# read -p reads from the pipe
read -p myvar
echo $myvar
bc tutorial in Number Processing Users Guide
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-07-2002 07:19 AM
тАО02-07-2002 07:19 AM
Re: bc
Lots of great ideas that I will use.
Thanks,
Again,
Bob