Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

search wildcard

Posted on 2003-11-10
12
Medium Priority
?
1,603 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 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