Batch file - finding a string in a text file

October 19, 2011 at 07:40:51
Specs: Windows XP
I wonder if someone can help me with this?

I need a way in a batch file to assign a variable to a string in a text file.

My text file looks like below (a user name - a space - then a postcode):

User1 postcode
User2 postcode
User3 postcode
User3 postcode

Basically I know I can use the findstr command to search for the user but I need some way to get findstr to look at the postcode entry for that user then assign it to a variable in the batch file. I'm sure there must be a way to make findstr find the space after the user and then look at the postcode.

Any help greatly appreciated.
Thank you.

See More: Batch file - finding a string in a text file

Report •

October 19, 2011 at 09:02:56
You can use findstr to identify the line, and then check this page out...

Report •

October 19, 2011 at 11:14:50
This should do what you're asking for - set User1 to equal the postcode following it and so on for each user in the list.

for /f "tokens=1-2 delims= " %%a in (yourtextfile.txt) do set %%a=%%b

Report •

Related Solutions

Ask Question