How do I pull a substring out of a file?

I'm new to shell scripting and am trying to write a small script that pulls a substring out of a file that has a few lines of text in it. The file will eventually have a lot of text, I just put a few lines in it for testing purposes.

Anyway, this is what I have so far...

#!/bin/ksh
 
top > testlog.txt
df -h >> testlog.txt
 
freeMem=`grep ",.*free mem," testlog.txt`
home=`grep "home" testlog.txt`

echo $freeMem
echo $home

as of now, it displays the entire line that the grep's return. I want to display just a substring out of each line that's returned from the two greps.

I've tried doing it two ways, but can't get it to work. Here's an example using my freeMem var:

Way 1: echo ${freeMem:22:2}
get an error saying something like bad substitution

Way 2: freeMem=`grep -o ",.*free mem," testlog.txt`
just doesn't work for me, says I can't us -o, but google says I should be able to.

Here's an example of the line that's in testlog.txt that the grep would return:

Memory: 16G phys mem, 11G free mem, 4103M swap, 4103M free swap

I want to display only the substring "11G".

Thanks in advance for any help.

echo 'Memory: 16G phys mem, 11G free mem, 4103M swap, 4103M free swap' | nawk '$1~ "^Memory"{print $5}'

thank you so much, works perfectly like this...

echo `grep ",.*free mem," testlog.txt` | nawk '$1~ "^Memory"{print $5}'

I'll have to learn nawk and awk

no need for echo AND grep:

nawk '/free mem,/ && $1~ "^Memory"{print $5}' testlog.txt

even better. thanks again.