@echo off for /f "tokens=4" %%a in ('dir hesp*.dns') do ( rem echo %%~na nslookup -q=NS %%~na >> hesperia.txt )