Solved

Need to get User Input and validate the input from file

Posted on 2011-02-22
7
403 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

803 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