2013-11-15 98 views
0

以下解析output.txt中,並獲得基於行新的SQL腳本文件output.txt中:批處理腳本從output.txt的

 
Changed database context to 'MY_DB'. 
name                                
-------------------------------------------------------------------------------------------------------------------------------- 
UserDomains                              
ApprovalConfiguration                           
ApprovalLevelRoles                            
CreditCardHolderTitle                           
ApprovalRole                              

(22 rows affected) 
name                                
-------------------------------------------------------------------------------------------------------------------------------- 
ApprovalConfigurationDelete                          
ApprovalConfigurationInsert                          
ApprovalConfigurationSelect                          
ApprovalConfigurationsSelectAll                         


(103 rows affected) 

SQL表的下面是名

 
UserDomains                              
ApprovalConfiguration                           
ApprovalLevelRoles                            
CreditCardHolderTitle                           
ApprovalRole 

...這是一個存儲過程的名稱

 
ApprovalConfigurationDelete                          
ApprovalConfigurationInsert                          
ApprovalConfigurationSelect                          
ApprovalConfigurationsSelectAll 

我想以某種方式來區分存儲過程表秒。 批處理腳本應該能夠產生一個SQL文件和填充它因此,在年底新的SQL文件表和存儲過程中的各行從output.txt的

應該是類似的東西:

 
-- TABLES 
exec sp_addarticle @publication = N'$(PublicationName)', @article = N'UserDomains', @type = N'logbased' 
GO 
exec sp_addarticle @publication = N'$(PublicationName)', @article = N'ApprovalConfiguration', @type = N'logbased' 
GO 
exec sp_addarticle @publication = N'$(PublicationName)', @article = N'ApprovalLevelRoles', @type = N'logbased' 
GO 
exec sp_addarticle @publication = N'$(PublicationName)', @article = N'CreditCardHolderTitle', @type = N'logbased' 
GO 
exec sp_addarticle @publication = N'$(PublicationName)', @article = N'ApprovalRole', @type = N'logbased' 
GO 

-- STORE PROCEDURES 
exec sp_addarticle @publication = N'$(PublicationName)', @article = N'ApprovalConfigurationDelete', @type = N'proc schema only' 
GO 
exec sp_addarticle @publication = N'$(PublicationName)', @article = N'ApprovalConfigurationInsert', @type = N'proc schema only' 
GO 
exec sp_addarticle @publication = N'$(PublicationName)', @article = N'ApprovalConfigurationSelect', @type = N'proc schema only' 
GO 
exec sp_addarticle @publication = N'$(PublicationName)', @article = N'ApprovalConfigurationsSelectAll', @type = N'proc schema only' 
GO 

感謝球員爲您提前幫助!下面

的血清

回答

0

批處理文件,做你想做的劃分,只是完成輸出細節。

@echo off 
setlocal EnableDelayedExpansion 

for /F %%a in (output.txt) do (
    set "line=%%a" 
    if "!TABLE!" equ "true" (
     if "!line:~0,1!" neq "(" (
     echo TABLE: !line! 
    ) else (
     set TABLE=false 
    ) 
    ) else if "!PROC!" equ "true" (
     if "!line:~0,1!" neq "(" (
     echo PROC: !line! 
    ) else (
     set PROC=false 
    ) 
    ) else if not defined TABLE (
     if "!line:~0,1!" equ "-" (
     set TABLE=true 
     echo -- TABLES 
    ) 
    ) else if "!line:~0,1!" equ "-" (
     set PROC=true 
     echo -- STORE PROCEDURES 
    ) 
)