Get separate used memory info from free -m command

You can use awk without the need for a separate grep pipe for this:

awk '/^Mem/ {print $3}' <(free -m)

Where records/rows are filtered for those beginning with Mem and the third field/column ($3) is printed for the filtered record.


As for the added question of displaying as percentage (based on jasonwryan's answer):

awk '/^Mem/ {printf("%u%%", 100*$3/$2);}' <(free -m)

get percentage by diving 3rd field by 2nd and print as an integer (no rounding up!).

EDIT: added double '%' in printf (the first one escapes the literal character intended for printing).


with bash free and grep only

read junk total used free shared buffers cached junk < <(free -m  | grep ^Mem)
echo $used