numbers.sh 347 Bytes
Newer Older
Sylvain Schmitz's avatar
Sylvain Schmitz committed
1 2 3 4
#!/bin/bash

file=$1
shift
5 6 7 8
total=`grep "$1" $file | wc -l`
#printf "& $total "
shift

Sylvain Schmitz's avatar
Sylvain Schmitz committed
9 10 11

while test ${#} -gt 0
do
12 13
    count=`grep "$1" $file | wc -l`
    percent=`bc <<< "100*$count/$total"`
Sylvain Schmitz's avatar
Sylvain Schmitz committed
14 15 16 17 18 19
    if [ $percent -lt 10 ]
    then
       printf "&  $percent\\%% "
    else
        printf "& $percent\\%% "
    fi
20
    #printf "& $count "
Sylvain Schmitz's avatar
Sylvain Schmitz committed
21 22 23
    shift
done