Computing.Net > Forums > Programming > Batch file search

Batch file search

Reply to Message Icon

Original Message
Name: Grusomhat
Date: December 14, 2005 at 12:21:08 Pacific
Subject: Batch file search
OS: XP
CPU/Ram: AMD Athlon 64 3000+ , 1g
Comment:

Hey everyone
I was wondering if there is any way to create a batch file that can search through a database in the batch file, and display results. ie If i wanted to search for pupils information at a school, i would type in the first or last name or a few letters and it would search through the database and display all names matching.

So Far I've got something that you have to type in the exact name but i want something les specific
Any ideas would be appreciated Thanks


Ignorance is Bliss but Knowledge is Power


Report Offensive Message For Removal


Response Number 1
Name: ghostdog
Date: December 14, 2005 at 19:21:00 Pacific
Subject: Batch file search
Reply: (edit)

what type of database ? most will have command line client. you can call the client in your batch file.


Report Offensive Follow Up For Removal

Response Number 2
Name: Grusomhat
Date: December 14, 2005 at 23:08:07 Pacific
Subject: Batch file search
Reply: (edit)

Hey sorry bout that maybe database wasn't the right word heres a batch file with what i meen hopefully it helps explain what i meen

@echo off
:user
cls
echo Please input the users EXACT login name(no CAPS)

set /p ans=%1
if "%ans%"=="john" GOTO:john
if "%ans%"=="jacob" GOTO:jacob
if "%ans%"=="george" GOTO:george
if "%ans%"=="harry" GOTO:harry
if "%ans%"=="mary" GOTO:mary
Echo Error you have spelt the username wrong or it isn't in our list
pause
cls
GOTO:user

:john
cls
echo Johns Information
Echo Phone Number:
Echo Address:
Echo Occupation:
pause
GOTO:endl

:jacob
cls
Echo Phone Number:
Echo Address:
Echo Occupation:
pause
GOTO:endl

:george
cls
Echo Phone Number:
Echo Address:
Echo Occupation:
pause
GOTO:endl

:harry
cls
Echo Phone Number:
Echo Address:
Echo Occupation:
pause
GOTO:endl

:mary
cls
Echo Phone Number:
Echo Address:
Echo Occupation:
pause
GOTO:endl

:endl
cls
Echo Would You like to Find Someone Elses Info
Echo 1) Yes
Echo 2) No

Set /p ans=%1
If "%ans%"=="1" GOTO user
IF "%ans%"=="2" exit

This is an example of the batch file so there is actually no database as such. i was wondering if there is any way to make it so that users didn't have to type in the exact name but they could just type in j or any other part of the name and it would come up with all the names it matches to the user inputed text. Hope you understand

Ignorance is Bliss but Knowledge is Power


Report Offensive Follow Up For Removal

Response Number 3
Name: wizard-fred
Date: December 15, 2005 at 02:43:46 Pacific
Subject: Batch file search
Reply: (edit)

There are databases and computer languges with the ability to find entries that 'sounds like' or 'is spelled similar to'. If you use any search engine you will see other methods of pattern matching.
In my early programming, I had a search based on the number of letters. Ex. Enter LE and it will first find a name equal to LE and if there was no match, then search names beginning with LE. If you entered B,C it looked for persons with last name beginning with B and first names beginning with C. The client was a doctor and wanted quick access to patient records. The computer gave a guick list to select from. Partial searches are relatively easy to implement.


Report Offensive Follow Up For Removal

Response Number 4
Name: ghostdog
Date: December 15, 2005 at 08:52:04 Pacific
Subject: Batch file search
Reply: (edit)

think you are better off using databases to store your user data...and get a more powerful language like Perl to do the job instead of batch. Perl have more powerful regex than in batch programmng..and other features you may find useful..


Report Offensive Follow Up For Removal

Response Number 5
Name: Grusomhat
Date: December 15, 2005 at 12:57:00 Pacific
Subject: Batch file search
Reply: (edit)

Hey Thanks for all the answers
i hopefully start using pearl and databases. One more question can pearl be called up from a batch fle

Ignorance is Bliss but Knowledge is Power


Report Offensive Follow Up For Removal


Response Number 6
Name: FishMonger
Date: December 15, 2005 at 14:54:03 Pacific
Subject: Batch file search
Reply: (edit)

A Perl script can be called from a batch file, but it would be more efficient to drop the batch file and do everything in Perl.


Report Offensive Follow Up For Removal

Response Number 7
Name: Grusomhat
Date: December 15, 2005 at 16:27:40 Pacific
Subject: Batch file search
Reply: (edit)

Ok Thanks Everyone For all you help

Ignorance is Bliss but Knowledge is Power


Report Offensive Follow Up For Removal

Response Number 8
Name: MediocreMan
Date: December 15, 2005 at 20:02:56 Pacific
Subject: Batch file search
Reply: (edit)

Hey Grusom you stole my stolen quote!


Report Offensive Follow Up For Removal

Response Number 9
Name: Grusomhat
Date: December 15, 2005 at 20:48:42 Pacific
Subject: Batch file search
Reply: (edit)

Hey MediocreMan Sorry Bout stealing you stolen qoute. Hopefully we can work this out so no one ends up in court

-Grusomhat, Your Local Hat Killer

Ignorance is Bliss but Knowledge is Power


Report Offensive Follow Up For Removal

Response Number 10
Name: MediocreMan
Date: December 15, 2005 at 21:40:09 Pacific
Subject: Batch file search
Reply: (edit)

I am Afraid that will not be possible grusom.
Prepare to be e-Terminated.
*sends ultra 1337 HaxX0r virus down to Grusoms Ip Adress*
that'll learn ya.


Report Offensive Follow Up For Removal

Response Number 11
Name: Grusomhat
Date: December 15, 2005 at 23:46:58 Pacific
Subject: Batch file search
Reply: (edit)

Oh thanks, Lucky my Firewall bounced it right back at your ip address along with confidential informatin -changes all passwords, whoops- I guess I'll be seeing you in court. -checks wallet- Um yeah nice talking to you, hopefully you have noticed i've changed my qoute.

Hope we can come to an agreement
-cyber handshake-


Never let school get in the way of your education


Report Offensive Follow Up For Removal

Response Number 12
Name: MediocreMan
Date: December 16, 2005 at 00:55:38 Pacific
Subject: Batch file search
Reply: (edit)

*accepts cyber handshake*
*lulls Grusom into false sense of security*
*uses automated packet flooder to attack Grusoms router,thus interupting Grusoms gay porn download*
Grusom slits wrist and dies in pool of blood/semen.

<insert witty/meaningful quote here>


Report Offensive Follow Up For Removal

Response Number 13
Name: Mechanix2Go
Date: December 16, 2005 at 02:34:10 Pacific
Subject: Batch file search
Reply: (edit)

I'm working on your BAT.


If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 14
Name: Grusomhat
Date: December 16, 2005 at 09:50:32 Pacific
Subject: Batch file search
Reply: (edit)

Hey Thanks Mechanix2Go


Ignorance is Bliss but Knowledge is Power


Report Offensive Follow Up For Removal

Response Number 15
Name: Mechanix2Go
Date: December 21, 2005 at 03:30:22 Pacific
Subject: Batch file search
Reply: (edit)

Hi Gh,

After spending several hours I came full circle to the original problem of doing it with the data contained within the BAT.

I don't see any way around having a separate file containing the data; since FIND is the obvious tool and it does it's FINDing in files.

I guess we're down to creating a 'file of data' on the fly.

This will demonstrate the desired flexability of using a partial string match.

::==== findstud.bat
@echo off

:main

set ID=
set /p ID=[name to find?]
call :lookup %ID%
goto :eof

:lookup

if "%ID%"=="" goto :eof
call :ulist %ID%
goto :main
goto :eof

:ulist

find /i "%ID%" < userlist.bat
if errorlevel 1 echo %1 not found && goto :eof
find /i /c "%ID%" < userlist.bat > # & set /p NUM=<#
if %NUM% GTR 1 echo %ID% was found in %NUM% records; be more specific && goto :eof
find /i "%ID%" < userlist.bat > found1
set /p currDATA=<found1
echo %currDATA%
call userlist.bat %currDATA%
goto :eof
:: DONE

Let me know if this is any help and whether you'd like to pursue it.


If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 16
Name: Mechanix2Go
Date: December 21, 2005 at 03:41:45 Pacific
Subject: Batch file search
Reply: (edit)

oops, forgot to include the userlist.bat.

Notice that in the userlist bat, the 'labels' have the spaces wrung out, since a space in a label is NG.

::=== userlist.bat
@echo off

goto %1

:mannysmith
echo many smith & goto :eof
:moejonson
echo moe jonson & goto :eof
:jacksmith
echo jack smith & goto :eof
:augiblutz
echo augi blutz & goto :eof
:maryjo
echo mary jo & goto :eof
:marysmith
echo mary smith & goto :eof
:marriannejones
echo marrianne & goto :eof
::===== DONE



If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal

Response Number 17
Name: Grusomhat
Date: December 21, 2005 at 14:35:11 Pacific
Subject: Batch file search
Reply: (edit)

Thanks M2G Thats Awesome. Yeh I'd love to pursue it, I'm going to look at it now and add some stuff in.

Ignorance is Bliss but Knowledge is Power


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch file search

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge