O script abaixo usa dois parâmetros: (endereço IP e nome do arquivo de entrada)
#!/bin/bash
echo "IP address: $1"
echo "Input file name: $2"
Count_IP=$(grep -c "$1" "$2" )
Count_IP_UN=$(grep "$1" "$2" |grep -c "UN")
echo "IP Count: $Count_IP"
echo "IP Count with UN: $Count_IP_UN"
Result=$(bc <<< "scale=1; $Count_IP_UN/$Count_IP"| awk '{printf "%0.1f", $0}')
echo "The result is: $Result"
Exemplo de execução:
$ ./CountRate.sh 127.0.0.1 inp.txt
IP address: 127.0.0.1
Input file name: inp.txt
IP Count: 2
IP Count with UN: 1
The result is: 0.5