Hi Experts!

Please help with the task:
A text file .sql contains DDL including 'create table', 'alter table', 'create index', 'drop table' and so on.
I am only interested in DDL for tables that have been altered, the example of the DDL I would like to extract:

alter table A add
ID numeric(22, 7)
;
commit
;
create index A_S on A
(ID) PCTFREE 30 ALLOW REVERSE SCANS
;
commit
;

alter table A add
NAME vargraphic(100)
;
commit
;
create index A_N on A
(NAME) PCTFREE 30 ALLOW REVERSE SCANS
;
commit
;


OS - Windows, using UNIX utilities for Windows (sed, gawk, grep...).

Steps:
1) find table names: grep "alter table" .sql >> tables_list.log

tables_list.log example:
A
A
B
C
D
D
D
D
...

2) using Windows 'for' loop to loop through tables_list.log and pass each table name into 'sed'

for /F %a in (tables_list.log) do sed -n "/%a/, /;/p" .sql >>1.log

The result 1.log is incorrect, it contains duplicates for some, but not for all 'alter table' statements.
Therefore, running 'uniq -u 1.log' and eliminating duplicates is not an option, because source file .sql contains multiple 'alter table A' statements.

Can someone tell where is the problem - incorrect 'sed' or Windows 'for' loop or both?

If this task can be done in Perl, please help a newcomer.


Thanks.