vlm
May 2, 2012, 6:50am
1
hello
i try to divide 2 variables in order to get a percentage--that's why i'm not interested in integer division--but nothing seems to work
I think awk is suitable for this but i'm not quite sure how to use it..
any ideas?
here's what I want to do:
percentage = varA/varB
thank you
Here is a simple example which show help you:
infile contents:
1 2
7 20
$ awk '{ printf "%d %d %2.2f%%\n" , $1, $2, ($1 * 100)/$2}' infile
1 2 50.00%
7 20 35.00%
vlm
May 2, 2012, 7:17am
3
fpmurphy:
Here is a simple example which show help you:
infile contents:
1 2
7 20
$ awk '{ printf "%d %d %2.2f%%\n" , $1, $2, ($1 * 100)/$2}' infile
1 2 50.00%
7 20 35.00%
thank you for your answer
my variables are not in a file so the command would look like this?
$ awk '{ printf "%d %d %2.2f%%\n" , $varA, $varB, ($varA/$varB}'
can I store the result in another variable?