I am having a file like below , which has many SQL statements. I want to read a particular block of SQL whenever needed.
MyFile.SQL
#QUERY1
SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON TAB OFF
SET VERIFY OFF
SET NUMFORMAT 99999999999999999
Select max(time_created) from test.table1 where cust=1;
EXIT;
#QUERY2
SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON TAB OFF
SET VERIFY OFF
SET NUMFORMAT 99999999999999999
Select count(*) from test.table1 where cust=1;
EXIT;
#QUERY3
SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON TAB OFF
SET VERIFY OFF
SET NUMFORMAT 99999999999999999
Select count(*) from test.table12 where acct=1;
EXIT;
I am using below command
x=$(cat test.sql )
echo $x | awk -F'COUNT_QUERY' '{ print $0 }'
Could someone help with some good approach to this?
Could you please try following, written and tested with shown samples in GNU
awk
.Explanation: Adding detailed explanation for above.