i have seen a couple of solutions to print between patterns but am unable to put things together to cater to my problem. I have a text file that contains a view definition as shown below and need to extract the definition between the first and last braces. Please note: there are open and closed braces in between which should be printed. any solution in awk or sed?
create view view_name
as(select column1 as someDATE,
column2,
column3,
substring(convert(char(19),(DATEadd(hh,8,column4)),121),12) as someTIME,
from table_name
where NAME in('test')
and column5='something')
Output reqired:
select column1 as someDATE,
column2,
column3,
substring(convert(char(19),(DATEadd(hh,8,column4)),121),12) as someTIME,
from table_name
where NAME in('test')
and column5='something'
Crude but effective:
sed -n -e '/(/,/)/p' filename | sed '1s/[^(]*(//;$s/)[^)]*$//'
EDIT:
(Corrected first solution.)
More sophisticated, but pulls the whole file into the hold space at once:
sed -n 'H;${x;s/^[^(]*(//;s/)[^)]*$//;p;}' filename