Solved

Need to get User Input and validate the input from file

Posted on 2011-02-22
7
382 Views
Last Modified: 2012-05-11
Need to get 3 digit numeric values and validate it with file.  If doesn't match, request input again.

Enter the person ID or Q to Cancel? 123
Match Found, Triggering action

Enter the person ID? 888
Match NOT Found, Please enter again or Q to Cancel.
0
Comment
Question by:sk7815
  • 4
  • 2
7 Comments
 
LVL 9

Accepted Solution

by:
Scottyworld earned 300 total points
ID: 34956675
This will automatically loop if the number is not found in the text file
 
@echo off

:TOP
set /p digits= Enter number: 

findstr /m "%digits%" "c:\support\myfile.txt"
If %errorlevel%==0 (
echo Found number
GOTO END
) else (
Echo Match not found
GOTO TOP
)
:END

Open in new window

0
 
LVL 8

Expert Comment

by:subhashchy
ID: 34956705
you should put your action stuffs after :END in the batch code provided by Scottyworld:
0
 

Author Comment

by:sk7815
ID: 34956903
Thank you, can you add 'Q" or 'q' to exit out.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:sk7815
ID: 34956921
may be '000' will work since we setting up as numeric.

@echo off

:TOP
set /p digits= Enter Store Number:

IF %digits% == 000 GOTO END

findstr /m "%digits%" "c:\junk\foo.dat"
If %errorlevel%==0 (
echo Found number
GOTO END
) else (
Echo Match not found
GOTO TOP
)
:END
0
 

Author Comment

by:sk7815
ID: 34956968
When the input value matches the string, it displays the file name.  Can we avoid it?
0
 
LVL 8

Assisted Solution

by:subhashchy
subhashchy earned 100 total points
ID: 34956986
add >nul after this line like this....

findstr /m "%digits%" "c:\support\myfile.txt" >nul
0
 

Author Closing Comment

by:sk7815
ID: 34957021
Great Team!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now