Convert bytes to Megabytes or Gigabytes for data coming from command

Solution 1:

numfmt is doing the bulk of the lifting below. You can tell it the format you want and additionally here I'm telling it to skip the first line, and focus on the second and third fields.

tail -n +2 /proc/net/dev \
| tr -d ':,|' \
| awk '{print $1 " " $2 " " $10}' \
| numfmt --to=iec --header=1 --field=2,3

If you want to get very much more complicated than that, or if you need this to perform better, I'd be looking to a real programming language. They all have available libraries (or built in functions) for doing this sort of stuff and they'll do it much faster.