Reputation: 136141
Consider the following DB schema:
CREATE UNIQUE INDEX blah1 ON table1(length);
CREATE INDEX blah2 ON table3(name);
CREATE INDEX blah3 ON table3 USING btree(id);
I want to write a small awk script that would return the names of the indices and tables, e.g.:
blah1, table1
blah2, table2
blah3, table3
I need to match the word that comes after the word INDEX
and the word that comes after the word ON
and ends with (
or whitespace.
Any idea how to do it using a regex match, without iterating over all $NF
s?
Upvotes: 1
Views: 582
Reputation: 4441
Works great with a Perl one-liner.
cat file | perl -ne '/INDEX ([a-zA-Z0-9]+) ON ([a-zA-Z0-9]+)/ && print "$1, $2\n";'
Returns what you wanted.
Upvotes: 0
Reputation: 359905
sed 's/.*INDEX \([^ ]*\) ON \([^( ]*\)[( ].*/\1, \2/' inputfile
awk '{sub(".*INDEX ","");sub(" ON ",",");sub("[( ].*",""); sub(",",", ");print}' inputfile
Upvotes: 0
Reputation: 879143
I don't know awk well, but this seems to work:
awk 'BEGIN{ FS="INDEX | ON "}{gsub(/[ (].*/,"",$3); print $2", " $3}' test.dat
Upvotes: 1