echo `./primecoind listtransactions "" 1000 | grep -A1 category | grep -A1 'immature\|generate' | grep amount | awk -F" " '{print $3}' | awk -F, '{printf "%s +",$1}'` 0 | bc
Edit: this doesn't account for sent.
If I'm not mistaken, the balance command alone (i.e. './primecoind balance') will give you the total of only mature blocks, but if you include the account parameter (i.e. './primecoind balance ""'), it will give you the total of all blocks, both mature and immature. All you have to do is subtract to see the immature balance alone, if I understand correctly what you are trying to do.