Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want my batch file to find a string in a file and return it to the next line in my batch file.

How can I do this? I've googled over and over but can't get the specific answer I need with the command to enter into my batch file. So for example

I have a document on desktop and it's called "PhoneNumbers.txt" And I want my batch file to find the string I'm searching for from the file and return it to my batch file for next step of batch file.

Desktop file is called "phonenumbers.txt" and inside is a list of people I know and their phone number. I want my batch file to search for a string say "Amanda P" and return only her number to my batch file so it enters the returned number into the line like

ECHO Amanda's phone number is __________ 

Ok so I can't explain it any easier or better so I hope someone understands and can help me with the exacr words to type into my batch file?

share|improve this question
Have you tried FindStr? Type FindStr /? into a command prompt for help – stib Jun 20 '14 at 13:49
up vote 0 down vote accepted

This code snippet should get you started:

@echo off
set /p string="Enter search string: " %=%
echo Looking for %string%...
findstr "%string%" phonenumbers.txt

In case it is not obvious %string% contains the text entered by the user.

How you extract the phone number from the output of findstr depends very much on how the line is formatted in the first place. If it is delimited in a sane way, then one possible solution would be to consider using the for command.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.