First it sets OFMT='%.2f%%', which means to change the output format so that it outputs real numbers with two decimal places followed by a percentage sign (as above). The END segment means to run the following command after you're done reading in standard input. (Unlike in some languages, awk's arrays can be labelled with text, not just numbers.) Whenever column 3 ($3) contains the word 'Capacity' ($3~/Capacity), it runs the command 'c=$5', which stores the fifth column into an array (a box) labelled with the contents of the third column. This awk command starts by reading in each line of ioreg -l, one at a time.
The printf command calculates $10/$5*100 (that is, the 10th column divided by the 5th column, times 100) and prints it as a floating-point number with 2 decimal places ('%.2f') followed by a percentage sign ('%%').Īwk '$3~/Capacity/ ' (So $5 is the 5th column's data and $10 is the 10th column's). This first awk command reads the standard input, one line at a time (if necessary I'm guessing only one line is being sent to it here), and splits the line into columns, the data in column c having the name $c.