level 2
不清楚你的实际文件,仅以问题中的说明为据
@璐村惂鐢ㄦ埛_000076K馃惥 off
rem 查找/搜索/匹配txt文件里包含/存在指定字符内容的行并根据下一行的内容是否符合指定特征进行相应修改
mode con lines=3000
set #=Any question&set @=WX/&set $=Q&set/az=0x53b7e0b4
title %#% +%@%%$%%$% %z%
cd /d "%~dp0"
powershell -NoProfile -ExecutionPolicy bypass ^
$fs=@(dir^|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});^
$text=[IO.File]::ReadAllLines($fs[0].FullName,[Text.Encoding]::Default);^
$f=$false;$n=2;^
[System.Collections.ArrayList]$s=@();^
for($i=0;$i -lt $text.count;$i++){^
if($f){^
if($text[$i] -eq 'B83'){^
if($text[$i+1] -ne $null){^
if($text[$i+1] -ne 'B84'){^
if($text[$i+1] -match '^^(B00^|B03)'){^
$text[$i]=$text[$i]+\"`r`nA\"+$n.toString();^
$n++;^
};^
if($text[$i+1] -match '^^A\d+'){^
$text[$i+1]='A'+$n.toString();^
$n++;^
};^
};^
};^
};^
};^
[void]$s.add($text[$i]);^
if($text[$i] -eq 'A1'){$f=$true;};^
};^
write-host ($text -join \"`r`n\");
:end
echo;%#% +%@%%$%%$% %z%
pause
2019年11月26日 15点11分