Click here for important information about

Copy word after a found string in batch

March 11, 2012 at 10:43:48
Specs: Windows 7
I feel this should be simple but can't find any answers elsewhere.

I'm trying to search a text file and when the string "MAC address =" is found output the text to a new text file. My code so far is as follows:

@echo off
color 0a
echo Please enter input filename:
set /p filein=
echo please enter output filename:
set /p fileout=
echo Please wait, generating list
for /F %%I in (%filein%) DO (nbtstat -A %%I | find /i "MAC")>>%fileout% && (echo ip= %%I)>> %fileout%

but obviously this only outputs the entire line the string is found on. I'm guessing tokens are involved but I'm too newbie to get it :S

thanks in advance for any help.

Note: The entire mini project that I'm trying to complete does the following:
one batch generates a list of IP addresses eg

 for /L %%I in (1,1,254) DO echo 192.168.0.%I >> %file% 

Then another uses this file as input to resolve the Mac address using nbtstat.
I then hope to merge the two to a 3rd text file and have a format similar to;5C59484586B1;(null);
ie IP;MAC address;hostname(optional)

Sorry if this seems overly complicated, I may have over explained myself!

See More: Copy word after a found string in batch

March 26, 2012 at 18:02:22
for /f "tokens=2 delims==" %%I in ('nbtstat -A %%I ^| findstr /i "MAC"') do ...


Report •
Related Solutions

Ask Question