-1

In the broader term, I need to parse SQL procedures and find what tables and columns the proc depends on. To do it, I am trying to search regex.

Example:

from table db..tb
where tb.column2 = "N" AND column 1 in ("ab","cd")

It should return

tb.column2

column1

How to do it using grep or awk or python script etc etc?

StefanS
  • 1,089
  • 1
  • 11
  • 38
  • What database are you using? Some provide this information in reference tables. For instance: https://technet.microsoft.com/en-us/library/ms345404(v=sql.110).aspx. – Gordon Linoff Jun 07 '16 at 13:46
  • Will you specify the exact format (example) of the input you have and the output format you want? – Michael Back Jun 07 '16 at 14:03

1 Answers1

0

My reading of your question is you have a table -- a delimited file -- where you want to check if a particular row has "N" in column 2 and either "ab" or "cd" being found anywhere in the string in column 1. The action you wish to trigger is to print the "N" followed by the value in column 1...

This example answer shows how to use both a check for "this == that" and regular expression comparison. It also shows how to modify the column delimiter.

awk -F "$delimiter" '$2 == "N" && $1 ~ /ab|cd/ { print $2; print $1 }'
Michael Back
  • 1,821
  • 1
  • 16
  • 17