I assume that the general question I have is, can I give awk a field separator, save one of the tokens in a variable, then give awk another field separator and save one of the tokens in the second variable, then print both values ββof the variables? It seems that the variables store a reference to the $ nth token, and not to the value itself.
A concrete example that I had in mind more or less follows this form: {Animal}, {species} class
Cat, Felis catus MAMMAL Dog, Canis lupus familiaris MAMMAL Peregrine Falcon, Falco peregrinus AVIAN ...
and you want it to output something like:
Cat MAMMAL Dog MAMMAL Peregrine Falcon AVIAN ...
Where what you want is what fits the form: {Animal} class
with something enclosed in {}, meaning that it can have any number of spaces.
My original idea: I would have something like this:
cat test.txt | awk '{FS=","}; {animal=$1}; {FS=" "}; {class=$NF}; {print animal, class}; > animals.txt
I expect the variable "animal" to keep what is to the left of the comma, and "class" to have a class type of this animal, so MAMMAL, etc. But what ends up is that only the last used Field Separator is applied, so that it will break for things that have spaces in the name, such as Peregrine Falcon, etc.
so it would look like
Cat, MAMMAL Dog, MAMMAL Peregrine AVIAN