不清楚你的实际文件/情况,仅以问题中的说明及猜测为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的文件放一起双击运行<# :
cls&echo off&cd /d "%~dp0"&set "current=%cd%"
rem 将一个txt文本文件里末尾包含有指定字符串的最后两行内容删除
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0'|Out-String|Invoke-Expression"
echo;%#% +%$%%$%/%_% %z%
pause
exit
#>
$current=$env:current;
$newfolder=$current+"\result";
if(-not (test-path -literal $newfolder)){[void][IO.Directory]::CreateDirectory($newfolder);}
$files=@(dir -literal $current|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
if($files.length -ge 1){
$enc=[Text.Encoding]::GetEncoding('GB2312');
$text=[IO.File]::ReadAllText($files[0].FullName, $enc).trim();
$m=[regex]::match($text, '.+\n.+$');
if($m.Success){
if($m.groups[0].value -match '</h2>'){
$text=$text.replace($m.groups[0].value, '');
}
}
$newfile=$newfolder+'\'+$files[0].Name;
[IO.File]::WriteAllText($newfile, $text, $enc);
}
温馨提示:答案为网友推荐,仅供参考