Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

search wildcard

Posted on 2003-11-10
12
Medium Priority
?
1,604 Views
Last Modified: 2008-02-01
Hi

I have the following script,  but I need to change the pattern from:
set PATTERN=ERROR.=.[1-9]

to

set PATTERN=.[1-9] error(s)

but the above syntax does not work, what is the correct syntax. For having a wildcard number before space then the word error(s) (the number cannot be 0)

@echo off
:: global parameters, please adapt as needed
set FOLDER=C:\test_search
set PATTERN=ERROR.=.[1-9]

set FOUND=0
pushd %FOLDER%
for /f "delims=" %%a in ('dir /b *.* ^|findstr /v "1."') do call :increment "%%a"
popd

echo Found occurences in %FOUND% files. Sending message...
if %FOUND% GEQ 1 (
  net send pc-000024 test-BAD
) else (
  net send pc-000024 test-GOOD
)
echo Message sent.
goto end

:increment
findstr /R "%PATTERN%" %1
if ERRORLEVEL 1 goto end
set /A FOUND=%FOUND%+1

:end
0
Comment
Question by:paulie99
  • 5
  • 4
  • 3
12 Comments
 
LVL 5

Expert Comment

by:brianadkins
ID: 9714883

.[1-9] error(s)

is a "regular expression" that means literally:

   any single character
   followed by a single digit number between 1 and 9
   followed by a space character
   followed by the word "error(s)"
   followed by a space character   (you have a trailing space above)

But, the command line for FINDSTR treats spaces as OR unless you tell it to take you literally... so it is looking for this:

   any single character
   followed by a number between 1 and 9  
       OR
   the word error(s)

So try this to get better results:

set PATTERN=.[1-9] error(s)
findstr /R /C:"%PATTERN%" %1

You may also want to get rid of the leading period in your pattern... this means that there must be a character (any character) BEFORE the number or you won't get a match.

Here is a great book on regular expressions, although you can find a lot out on the web...
http://www.amazon.com/exec/obidos/tg/detail/-/0596002890/qid=1068471988/sr=8-1/ref=sr_8_1/002-1835265-5292003?v=glance&n=507846

-Brian Adkins

0
 

Author Comment

by:paulie99
ID: 9715077
Hi

Thanks for the feedback Brian, I have tried your example but with no joy. to repeat my question:

I have the following script,  but I need to change the pattern from:
set PATTERN=ERROR.=.[1-9]

to

set PATTERN=.[1-9] error(s)

but the above syntax does not work, what is the correct syntax. For having a wildcard number before space then the word error(s) (the number cannot be 0)



@echo off
:: global parameters, please adapt as needed
set FOLDER=C:\search_test\testUDebug2.txt
set PATTERN=.[1-9] error(s)
set FOUND=0
pushd %FOLDER%
for /f "delims=" %%a in ('dir /b *.* ^|findstr /v "1."') do call :increment "%%a"
popd

echo Found occurences in %FOUND% files. Sending message...
if %FOUND% GEQ 1 (
  net send pc-000024 test-BAD
) else (
  net send pc-000024 test-GOOD
)
echo Message sent.
goto end

:increment
findstr /R /C:"%PATTERN%" %1
if ERRORLEVEL 1 goto end
set /A FOUND=%FOUND%+1

:end
0
 
LVL 5

Expert Comment

by:brianadkins
ID: 9715099

Simply repeating the question will not increase the odds of a helpful answer...

I would suggest posting the actual contents of the file you are trying to query.

-Brian Adkins
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

Author Comment

by:paulie99
ID: 9715237
Hi

I'm using the above script to search a file which will contain the  text similar to the following:
--------------------Configuration: Aerotech - Win32 Debug--------------------
Compiling...
Aerotech.cpp
CAerotech.cpp
MachiningStage.cpp
U500Controller.cpp
Generating Code...
Linking...
   Creating library Debug/Aerotech.lib and object Debug/Aerotech.exp
Performing registration

Aerotech.dll - 0 error(s), 0 warning(s)

It is the above line which I'm concerned with as I want to able to have my script to search file and define whether this line contains:
0 erros(s)

or

9 error(s)

For if it contains 1 or more error(s) then the result should be a netsend of test-bad. If it is zero then the netsend message should be test-ggod.
0
 
LVL 5

Expert Comment

by:brianadkins
ID: 9715327

This works here....  

I changed the pattern to get rid of the "(s)"  ... not needed
and the leading period.

:::::::::::::::::::::::::::::::
@echo off
:: global parameters, please adapt as needed
set FOLDER=C:\test_search
set PATTERN=[1-9].error

set FOUND=0
pushd %FOLDER%
for /f "delims=" %%a in ('dir /b *.* ^|findstr /v "1."') do call :increment "%%a"
popd

echo Found occurences in %FOUND% files. Sending message...
if %FOUND% GEQ 1 (
  net send pc-000024 test-BAD
) else (
  net send pc-000024 test-GOOD
)
echo Message sent.
goto end

:increment
findstr /R "%PATTERN%" %1
if ERRORLEVEL 1 goto end
set /A FOUND=%FOUND%+1

:end
:::::::::::::::::::::::::::::::

-Brian
0
 
LVL 16

Assisted Solution

by:_nn_
_nn_ earned 2000 total points
ID: 9715403
Hi Paulie,

Are you sure of this ?

set FOLDER=C:\search_test\testUDebug2.txt

That should be a folder name, not a file name. If you need to parse specific files, you could do something like :

@echo off
:: global parameters, please adapt as needed
set FOLDER=C:\search_test
set MASK=*.*
:: or do you rather mean  ?
:: set MASK=testUDebug2.txt
set PATTERN=.[1-9] error(s)
set FOUND=0
pushd %FOLDER%
for /f "delims=" %%a in ('dir /b %MASK% ^|findstr /v "1."') do call :increment "%%a"
popd

echo Found occurences in %FOUND% files. Sending message...
if %FOUND% GEQ 1 (
  net send pc-000024 test-BAD
) else (
  net send pc-000024 test-GOOD
)
echo Message sent.
goto end

:increment
findstr /R /C:"%PATTERN%" %1
if ERRORLEVEL 1 goto end
set /A FOUND=%FOUND%+1

:end
0
 

Author Comment

by:paulie99
ID: 9715438
Hi

I'm operating on an NT environment, and this script just returns a netsend test-good message no matter what value is put before the word error????

0
 
LVL 5

Expert Comment

by:brianadkins
ID: 9715458

Have you run it without "@echo off" to see what is actually happening behind the scenes?

-Brian
0
 
LVL 16

Expert Comment

by:_nn_
ID: 9715874
The /C:"" option for findstr should work ok on NT too. But in case of, I'd try to "tune" Brian's last idea like this :

@echo off
:: global parameters, please adapt as needed
set FOLDER=C:\search_test
set MASK=*.*
:: or do you rather mean  ?
:: set MASK=testUDebug2.txt
:: Following would misinterpret "10 errors"
:: set PATTERN=[1-9].error
set PATTERN=[^0-9][1-9][0-9]*.error(s)
set FOUND=0
pushd %FOLDER%
for /f "delims=" %%a in ('dir /b %MASK% ^|findstr /v "1."') do call :increment "%%a"
popd

echo Found occurences in %FOUND% files. Sending message...
if %FOUND% GEQ 1 (
  net send pc-000024 test-BAD
) else (
  net send pc-000024 test-GOOD
)
echo Message sent.
goto end

:increment
findstr /R "%PATTERN%" %1
if ERRORLEVEL 1 goto end
set /A FOUND=%FOUND%+1

:end

0
 

Author Comment

by:paulie99
ID: 9716049
Hi

I took the above script and applied it to the log file:
--------------------Configuration: Aerotech - Win32 Debug--------------------
Compiling...
Aerotech.cpp
CAerotech.cpp
MachiningStage.cpp
U500Controller.cpp
Generating Code...
Linking...
   Creating library Debug/Aerotech.lib and object Debug/Aerotech.exp
Performing registration

Aerotech.dll - 9 error(s), 0 warning(s)

But got the net send message of test-good back no matter what value I put before the word error(s)
?????
When I specified the txt file in one ogf the above scripts it was to simply the situation to search only one specified file.
0
 
LVL 16

Accepted Solution

by:
_nn_ earned 2000 total points
ID: 9716208
%$@#!!

That findstr thingie is slowly getting on my nerves... Paulie, would you mind using some real regexp tool like grep ?
Anyway, I tested that one, and it seems ok :

@echo off
:: global parameters, please adapt as needed
set FOLDER=C:\search_test
set MASK=*.*
:: or do you rather mean  ?
:: set MASK=testUDebug2.txt
:: Following would misinterpret "10 errors"
:: set PATTERN=[1-9].error
set PATTERN=\^<[1-9][0-9]*.error(s)
set FOUND=0
pushd %FOLDER%
for /f "delims=" %%a in ('dir /b %MASK% ^|findstr /v "1."') do call :increment "%%a"
popd

echo Found occurences in %FOUND% files. Sending message...
if %FOUND% GEQ 1 (
  net send pc-000024 test-BAD
) else (
  net send pc-000024 test-GOOD
)
echo Message sent.
goto end

:increment
findstr /R "%PATTERN%" %1
if ERRORLEVEL 1 goto end
set /A FOUND=%FOUND%+1

:end
0
 

Author Comment

by:paulie99
ID: 9716424
Hi _nn_

as always you come up trumps.

I will spilt the points in your favour with Brian.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Integration Management Part 2
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month5 days, 20 hours left to enroll

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question