Batch File Search Text File

Microsoft Windows vista business w/ sp1...
March 16, 2010 at 12:42:48
Specs: Windows Vista
I am making a batch file that searches a text file of a list of data like this:

Name: John
Age: 34
Weight: 67
Height: 34
Gender: Male

Name: Sarah
Age: 28
Weight: 15
Height: 23
Gender: Female

When the user enters the name "John" it displays John's name, age, weight, height, and gender. My problem is that when you enter a name that doesn't exist, it displays some random lines. I have no idea why. I came up with a solution by putting "NO SUCH NAME EXISTS!" in those lines, but it did not seem like a very elegant way to solve the problem, and it doesn't always work.

Here is my code:

@echo off
cls
echo.
echo.
echo Whose information do you want to see?
set /p name=Enter your choice here: %
find /n "Name: %name%" store.txt | findstr /v STORE >temp.txt
for /f "tokens=1 delims=[]" %%a in (temp.txt) do echo %%a >temp2.txt
set /p number= <temp2.txt
find /v /n "" store.txt >temp3.txt
set /a number= %number%+0
find "[%number%]" temp3.txt | findstr /v TEMP3 >temp4.txt
set /a number= %number%+1
find "[%number%]" temp3.txt | findstr /v TEMP3 >>temp4.txt
set /a number= %number%+1
find "[%number%]" temp3.txt | findstr /v TEMP3 >>temp4.txt
set /a number= %number%+1
find "[%number%]" temp3.txt | findstr /v TEMP3 >>temp4.txt
set /a number= %number%+1
find "[%number%]" temp3.txt | findstr /v TEMP3 >>temp4.txt
for /f "tokens=2*" %%a in (temp4.txt) do echo %%a %%b
cls > temp.txt
cls > temp2.txt
cls > temp3.txt
cls > temp4.txt


See More: Batch File Search Text File

Report •


#1
March 16, 2010 at 12:45:44
Sorry, this is in the wrong category. Is there a way to move it?

Report •
Related Solutions


Ask Question