I'm trying to search and extract the sentences that start with a particular keyword, and which exist between/starts/ends with a keyword. The intention is to extract sentences starting with 'ALTER TABLE', which are either nested between 'GO' keyword or have GO on begin or end block of it. The number of sentences that exist between GO keyword could be arbitrary. Here is my sample file and the code that was written to achieve it.
Content of SampleFile.sql
ALTER TABLE [dbo].[test1]
ADD [country] VARCHAR (30) NULL;
some procedure code
PROCEDURE ALTER TABLE;
ALTER TABLE [dbo].[test2]
ADD [continent] VARCHAR (30) NULL;
$path = 'D:\Script'
$sampleFile = 'SampleFile.sql'
$search = "ALTER TABLE"
(GC $path\$sampleFile -Delimiter 'GO') -match "^$search*"