This works with both gam csv and gam batch.
For all you command line hacks and scripters: I regularly deal with situations where I have to do the same gam thing to 140 items that are not dependant on each other. It is easy enough to to for loops on a command line, but in some cases, that ends up taking a long time. To speed things up, I do this:
$ (for A in 1 2 3 4 5 6 7 8; do
echo gam whatever argument argument2 ${A} argument3
done ) | gam batch -
You need to be careful with arguments that have spaces and quoting etc and when one or more processes throw errors it becomes difficult to figure out what happened, but for simple cases you can take advantage of concurrent (i.e. parallel) processes. The 'magic' lies in the use of the brackets: known in bash parlance as a 'subshell' it is a way to group a number of commands and have all their output bundled as if there was only one. Whatever happens within a subshell stays there, so you automatically get protection from scope conflicts and you can mess with environment variables without having to manually restore them. For example:
$ gam info something something csv
will output data in a csv format. If you wanted to grab those data elements and do something with them, you could do:
$ gam info something something csv | awk -F',' '{print $2 $3}' | while read FirstDataElement SecondDataElement; do
echo "This is the first: ${FirstDataElement}"
echo "This is the secondt: ${SecondDataElement}"
done
The awk bit chops up the csv line and spits out the second and third element, which you use as first and second, respectively.
Easier way with a subshell:
$ gam info something something csv | (
IFS=","
while read DUMMY FirstDataElement SecondDataElement; do
echo "This is the first: ${FirstDataElement}"
echo "This is the secondt: ${SecondDataElement}"
done)
The DUMMY catches (and ignores) the first item on the line; the rest of the command is identical. By changing the Internal Field Seperator (IFS) from the default space(s)/tab(s) to a comma, we let bash do the splitting of the csv line; no awk needed. Because the subshell ends (and disappears) after the closing ), there is no need to (re)set the IFS.
--peter