查找记事本中变量的批处理

来源:百度知道 编辑:UC知道 时间:2024/06/17 17:52:33
比如,在一个文件夹中有个批处理文件和一个记事本(记事本中的内容是网卡和计算机名的对应关系) 批处理的功能是获取本机网卡地址然后从记事本中查找网卡和计算机名的对应关系, 从而来改计算机名 !

假设,文本文件为file.txt,内容为:
aa-bb-cc-dd-ee-ff computer1
即网卡地址在前,计算机名在后,空格为分隔符

则查找计算机名的语句为:

@echo off

set file_namelist=file.txt

set computer_name=

for /f "tokens=1 skip=3" %%a in ('getmac') do for /f "tokens=1*" %%j in ('findstr "%%a" %file_namelist%') do set computer_name=%%k

echo "%computer_name%"