Find number from a line and get the quotient

text processing

Users of Digital_A803x_433Mbps: (Total of 2784 licenses issued; Total of 314 licenses in use)

In above example line of text, I would like to get the percentage of available licenses, so the output would be: 88.27% which is the quotient of license in use and licenses issued: (314/2784) * 100 – 100.

Best Answer

Using AWK:

$ echo 'Users of Digital_A803x_433Mbps: (Total of 2784 licenses issued; Total of 314 licenses in use)' |
awk '{ printf "%2.2f%%\n", 100 - $11 / $6 * 100 }'
88.72%

This assumes that there are no spaces in the label (“Digital_…”).

Related Question