Hacky solution, yes one could merge most of these things, also just doing this in awk might be nicer. The final sed is because some commands (training siege) seem to list the entities this applies to last instead of first (which doesn't matter, but makes this a bit longer than it should be.
I'm not sure why you have numbers, then xN in that list, nor do I really care, but yes one can figure that out from a commands.txt file. For a proper solution one would also need to handle cancellations, and possibly parse the json for each command to make sure the order doesn't matter.
grep "cmd 1" commands.txt | grep "train" | sed 's/^.*units\///' | sed 's/","count":/ /' | sed 's/}$//' | sed 's/,"entities.*$//'