Need to get average idle time using mpstat

I want to get average idle time of the server using mpstat. The problem I am having is %idle is not in same columns in all the versions of linux.

example 1:

example 2:

I tried below command as generalized solution but as Average as one less column output is not proper.

I am getting below output.

But the desired output is

Thanks

See if this will do what you want.

mpstat 1 2 | awk '
    /%idle/ {for(i=1; i<=NF; i++){if($i=="%idle"){idle=i;break}}}
    $1 ~ /^(0[0-9]|1[12]):/ {print $idle;next}
    $1 ~ /Average/ {print $(idle -1)} '