Search Text File and Echo

May 10, 2011 at 23:20:44
Specs: Windows 7
Very sorry if this has been asked before.
I have been trying to locate the correct solution, but nothing seems to match my situation.

Want to find a way to have the batch file take the users input and search a text file and echo the entire line or lines if located.

I have the "set /P Name=" part down. User Enters - John Doe (would be name only)

Then search Text File - \\Database\customers.txt for that name.

The file is formated like:
John Doe 01/01/1990 M Level1
John Doe 02/01/1990 M Level1
Jane Doe 02/02/1980 F Level2
James Doe 07/01/1970 M Level3

If a match is found, display those lines in the batch file.

So the results would be:

Customer Found:
John Doe 01/01/1990 M Level1
John Doe 02/01/1990 M Level1


Thanks


See More: Search Text File and Echo

Report •


#1
May 11, 2011 at 07:50:05
Untested:
set /P Name=
echo Customer Found:
findstr "%Name%" "\\Database\customers.txt"
if "%errorlevel%=="1" echo None

When your only tool is a hammer, every problem looks like a nail.


Report •

#2
May 13, 2011 at 18:17:10
Thanks orangeboy, that got me 95% there.

Only issue I have now is, if I search for mark smith (for example) I get all "mark" and "smith" in the text. So I got mark smith, mark Johnson and bill smith coming yo the search works but with 3000 names in the text, i want to narrow it down

Is there any way to narrow it down and have it check both names then return result?


Report •

#3
May 13, 2011 at 18:30:45
Think I found the solution.

findstr /b /I /C:"%Name%" "\\Database\customers.txt"


Report •

Related Solutions


Ask Question