troubleshooting Question

Extracting Elements from a line in a file in a Windows Batch Scirpt

Avatar of Julie Kurpa
Julie KurpaFlag for United States of America asked on
Windows OSWindows BatchPowershell
23 Comments1 Solution124 ViewsLast Modified:
Using Windows Batch Scripting, I'm working to pull certain strings from an error log so I can build a SQL Statement.  

So far, I've gotten what I need into a file on one continuous line.  It should be that way each time I pull in an error.  I'm interested in pulling out only the UPDATE statements and certain elements related to each one.

The line may contain one or several INSERT, UPDATE or DELETE statements peppered throughout so it's very tough to decide what to search for.  

As I pull in the strings I want for each UPDATE statement, I'll build the SQL and call a stored procedure to do what I need to do.  Then return to the Batch Script to get the next UPDATE statement (if there is one).

I've already managed to get a Count of the number of UPDATE statements so I can use that for a loop.

The line below is an example of what I've managed to place in a file (all one continuous line).

} SQL Exception (state )(using SQL: "[UPDATE owner.tableName SET i_unwanted_column1=yyyy,i_unwanted_column2=yyy,i_unwanted_column3=yyyyy,d_unwanted_column4=to_timestamp('1900-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss.ff3') WHERE i_pkey_column = yyyyy , UPDATE owner.tableName SET i_unwanted_column1=xxxx,i_unwanted_column2=xxxx,i_unwanted_column3=xxxxx,d_unwanted_column4=to_timestamp('2018-10-29 00:00:00','yyyy-mm-dd hh24:mi:ss.ff3') WHERE i_pkey_column = xxxxxx ]"):

I need to extract the "owner", "tableName" (found after the UPDATE), the primary key column name and it's value (located after the WHERE) for each UPDATE statement.

I've been looking at many websites but none have helped me put together something that I can get to work.

I'm a novice at Windows Batch scripting and only now exploring Powershell.  In fact, it's with powershell that I've been able to extract the line I need from the error log into a file all on one line and count the number of UPDATE statements.  :)

Thank you.
"Batchelor", Developer and EE Topic Advisor
Join our community to see this answer!
Unlock 1 Answer and 23 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 23 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros