I'm trying to parse through some massive SQL query logs using sed and want to extract the names of all the tables that are joined in each query. Here's what I'm trying:
echo '[SQL_STMT="SELECT A FROM TABLEA JOIN TABLEB ON SOMETHING JOIN TABLEC ON SOMETHINGELSE WHERE A = 1"]' \
| sed -e 's/SQL_STMT=.*JOIN \([A-Z0-9_]*\) .*\]$/SQL_JOINS="\1"]/g'
but this only returns the following:
[SQL_JOINS="TABLEC"]
what I'd like to see is something like this:
[SQL_JOINS="TABLEB TABLEC"]
and have it work for any number of joins
So how do I structure the backreference so that it gets all the joined tables?