Your first gam command will return a file containing all of the FQDN email addresses of all the groups in the domain, so far so good.
Your second command starts to go off at the "update" token. It should read "update ~email", that will tell gam which group you want to update. The remainder will expand into something like "email
some...@somedomain.com.au^(.+)@.*$
1...@newdomain.com.au".
I suggest a three step approach. The first command will get you your current set of groups, next you need to pass it through a filter that will output a new csv file with two columns: oldgroup,newgroup and each line maps the old group to the new. This can be easily accomplished with tools like awk, python, or for the brave bash shell. I'm not sure what to recommend since the execution environment isn't specified. Here's an example using a *nix bash environment.
> gam print groups > printgroups.csv
> (echo "oldgroup,newgroup";tail +2 printgroups.csv |gawk -e '{split($1,a,"@",s);print( $1","a[1]"@newdomain.au");}') > updateGroups.csv
> gam csv updateGroups.csv update ~oldgroup email ~newgroup
As noted previously there are other methods, Python to read the initial csv and output a new one.
Hope that's useful,
-Marsh
--
Maj Marshall E Giguere
NH Wing Director of IT
Civil Air Patrol, U.S. Air Force Auxiliary
Volunteers serving America's communities, saving lives, and shaping futures.