您把下面这段批处理存为setaccount.bat,与a.txt和b.txt放在同一个文件夹下,运行就行了,您试试看。
@echo off
@setlocal enabledelayedexpansion
@ren b.txt _b.txt
@for /f "tokens=1,2* delims==" %%i in (a.txt) do (
@set pcname=%%j
@set pwd=%%i
@if %computername%==!pcname! (
@for /f "delims=" %%k in (_b.txt) do (
@set ln=%%k
@if !ln!==宽带账号: (
@echo 宽带账号:%computername% >> b.txt
) else (
@if !ln!==宽带密码: (
@echo 宽带密码:!pwd! >> b.txt
) else (
@echo !ln! >> b.txt
)))))
if not exist b.txt (
@ren _b.txt b.txt
) else (
@del _b.txt /f /q >nul
)
很简单的,两个for语句欠套,用=做提取文本的分隔符分析文本,两个echo写入b文件就行了