Math action in ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Math action in ksh
# 1  
Old 07-19-2011
Tools Math action in ksh

Hello,
I want to do div action in ksh and get the full result(with leftover).

i.e.
4/3=1.33
and not
4/3=1
# 2  
Old 07-19-2011
Code:
 echo "scale=2; 4 / 3" | bc

This User Gave Thanks to pravin27 For This Post:
# 3  
Old 07-19-2011
Code:
 
$ echo "4 3" | nawk '{printf("%0.4s\n",$1/$2)}'
1.33

# 4  
Old 07-19-2011
Code:
$ printf "%2.2f\n" $(( 4.0/3 ))
1.33

# 5  
Old 07-19-2011
With some versions even:

Code:
zsh-4.3.11[radoulov]% ksh -c 'print ${.sh.version}; printf "%2.2f\n" 4.0/3'
Version JM 93t+ 2010-06-21
1.33

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh field math

Hi, I have a text like with many rows of data like: 7a,0,1182 7a,1,1040 7b,0,483 7b,1,242 7c,0,224 7c,1,877 I need to be able to take the value of the first field (i.e. 7a) and if there are multiples, add the value of the third field, (1182 + 1040) and insert the output of all of this in... (2 Replies)
Discussion started by: scriptr2be
2 Replies

2. Shell Programming and Scripting

multiple action!

lets explain it easy by showing the initial file and desired file: I've a file such this that contains: initial_file: 31/12/2011 23:46:08 38.6762 43.689 14.16 Ml 3.1 ... (1 Reply)
Discussion started by: oreka18
1 Replies

3. Shell Programming and Scripting

ksh date math

I have a requirement to remove all files from a directory execpt those > (now -N hrs). Once I can figure out how to calculate (now -N hrs) I was thinking of creating a temporary file with that time (now-N hrs) than using the find and -newer option. Does anybody have any KSH code (needs to... (3 Replies)
Discussion started by: BeefStu
3 Replies

4. Shell Programming and Scripting

Need help with find its action

I am writing a shell script that takes at least 2 arguments. The first is an octal representation of file permissions, the second is a command that is executed on all the files found with that permission. #!/bin/sh find . -perm $1 -exec $2 $3 $4 {} \; invoked: ./script.sh 543 ls -la what... (3 Replies)
Discussion started by: computethis
3 Replies

5. Shell Programming and Scripting

same action in then as in else: explanation?

in /etc/init.d/networking of an ubuntu computer, I found this code: if ifdown -a --exclude=lo; then log_action_end_msg $? else log_action_end_msg $? fi Shouldn't it be replace by ifdown -a --exclude=lo ... (0 Replies)
Discussion started by: raphinou
0 Replies

6. Shell Programming and Scripting

Why won't my Ksh do math with (( ))?

Hello, I'm usring Ksh on AIX 5.3. For some reason my K-Shell gives me an error when I try to use the math operators (( )). Can anyone tell me what's going on and how to fix it? Thanks so much! My K-Shell: />ls -al /usr/bin/ksh -r-xr-xr-x 5 bin bin 237420 Apr 10... (2 Replies)
Discussion started by: troym72
2 Replies

7. Shell Programming and Scripting

action command

Hi.. When i refered the script /etc/rc.sysinit... i found the "action commands" like But this is not working in my shells.. the following error is coming... Please anybody help Thanks in advance esham (5 Replies)
Discussion started by: esham
5 Replies
Login or Register to Ask a Question