Using multiple strings for FINDSTR - is this OK?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Using multiple strings for FINDSTR - is this OK?

#1 Post by SIMMS7400 » 17 Mar 2021 03:15

Hi Folks -

I have the following logic that I need to check multiple strings. If 1 or more are found from my first check, then need to include other and spool all content to a file. The logic is working but wondering if there is a better way? Also, I'd like to use ORA- as one of my strings but the "-" bombs it, why?

Here is my logic:

Code: Select all

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

::-- Critical Errors to Check First --::
SET "DM_CRITICAL_CHK="ORA" "Fetch of Driver Member" "Error: 3303" "Error: 3304" "Error: 3333" "Error: 3335" "Error: 3336" "Error: 3337" "does not exist for the specified cube or you do not have access to it" "Outline data store load process finished""

::-- Additional Strings to include if 1 or more Critical Errors found --::
SET "DM_ALL_CHK="FDMEE Process:" "Location     :" "Period Name  :" "Category Name:" "Rule Name    :" !DM_CRITICAL_CHK!"

::-- If one or more Data Management CRITICAL Errors detected, build kickout file --::
FINDSTR /IC:!DM_CRITICAL_CHK! "test.log" && (
	FOR %%A IN (!DM_ALL_CHK!) DO (
		FOR /F "tokens=* delims=" %%a IN (
			'FINDSTR /C:"%%~A" "test.log"'
		) DO ECHO %%a>>"out.txt"
	)
)
	
pause
Here is my sample file:

Code: Select all

2021-03-16 22:04:35,737 INFO  [AIF]: FDMEE Process: 9, Log Level: 5
2021-03-16 22:04:35,737 INFO  [AIF]: Location     : Location (Partitionkey:2)
2021-03-16 22:04:35,737 INFO  [AIF]: Period Name  : Jan-20 (Period Key:1/31/20 12:00 AM)
2021-03-16 22:04:35,737 INFO  [AIF]: Category Name: Actual (Category key:1)
2021-03-16 22:04:35,737 INFO  [AIF]: Rule Name    : Actual_Emp (Rule ID:10)
| Error: 3303 | S23585 | "1380-01","E10","Current","S23585","Actual","FY20","Sep",7088.4 | 
| Error: 3303 | S23585 | "1380-03","E10","Current","S23585","Actual","FY20","Sep",9198.81 | 
| Error: 3303 | S23585 | "1380-04","E10","Current","S23585","Actual","FY20","Sep",2764.05 | 
| Error: 3303 | S23585 | "1999-01","E10","Current","S23585","Actual","FY20","Sep",-19051.26 | 
| Error: 3303 | S23585 | "1100-03","E10","Current","S23585","Actual","FY20","Oct",-203.89 | 

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Using multiple strings for FINDSTR - is this OK?

#2 Post by SIMMS7400 » 17 Mar 2021 04:08

In searching some old threads from Fox and others, this seems to be the preffered approach:

Code: Select all

@ECHO OFF

::-- If one or more Data Management CRITICAL Errors detected, build kickout file --::
FINDSTR /I /C:"ORA-"^
		   /C:"Fetch of Driver Member"^
		   /C:"Error: 3303"^
		   /C:"Error: 3304"^
		   /C:"Error: 3335"^
		   /C:"Error: 3336"^
		   /C:"Error: 3337"^
		   /C:"does not exist for the specified cube or you do not have access to it"^
		   /C:"Outline data store load process finished"^
		   "test.log" && (
	FINDSTR /I /C:"FDMEE Process:"^
			/C:"Location     :"^
			/C:"Period Name  :"^
			/C:"Rule Name    :"^
			/C:"ORA-"^
		    /C:"Fetch of Driver Member"^
		    /C:"Error: 3303"^
		    /C:"Error: 3304"^
		    /C:"Error: 3335"^
		    /C:"Error: 3336"^
		    /C:"Error: 3337"^
		    /C:"does not exist for the specified cube or you do not have access to it"^
		    /C:"Outline data store load process finished"^
		    "test.log">>out.txt
	)
)
I just don't like how I need to maintain the same value twice, hence the reason for my variables in my original post. Is that still possible? THanks!

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Using multiple strings for FINDSTR - is this OK?

#3 Post by dbenham » 17 Mar 2021 06:59

Variables to the rescue

Code: Select all

@echo off
setlocal

::-- Define search strings
set critical=/I^
  /C:"ORA-"^
  /C:"Fetch of Driver Member"^
  /C:"Error: 3303"^
  /C:"Error: 3304"^
  /C:"Error: 3335"^
  /C:"Error: 3336"^
  /C:"Error: 3337"^
  /C:"does not exist for the specified cube or you do not have access to it"^
  /C:"Outline data store load process finished"
set kickout=%critical%^
  /C:"FDMEE Process:"^
  /C:"Location     :"^
  /C:"Period Name  :"^
  /C:"Rule Name    :"

::-- If one or more Data Management CRITICAL Errors detected, build kickout file --::
findstr %critical% "test.log" && findstr %kickout% "test.log" >>out.txt

Dave Benham

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Using multiple strings for FINDSTR - is this OK?

#4 Post by SIMMS7400 » 22 Mar 2021 19:22

Dave -

As usual, you are the man! Thank you so much for your help here! This has actually cascading into my updating a few of my other scripts as well based on the concept here.

Thank you again!!

Post Reply