I have lines in a file that are comma separated. There are no column headers, it's mostly comma separated 'name=value' pairs. Here is some test data:
listoffruits,producelist,APPLE=red,BANNANA=yellow,GRAPE=purple,ORANGE=orange,FRUIT=yes,WATERMELON=green
listoffruits,producelist,APPLE=red,BANNANA=yellow,GRAPE=violet,ORANGE=orange,FRUIT=affirmative,WATERMELON=green
I would like to get the value for GRAPE=* and FRUIT=* to get the result:
purple yes
violet affirmative
Also I would like the ability to add more "columns" later (so not always GRAPE, FRUIT, but GRAPE, FRUIT and WATERMELON)
Another snag is the columns are not fixed. So I don't always know that WATERMELON is the last column.
The closest I got was from @jasonwryan:
awk -v RS="," -F= '/GRAPE/{a=$2}; /FRUIT/{b=$2} END{print a,b"\n"}'
but this outputs the last line "violet affirmative" and not:
purple yes
violet affirmative