@ECHO OFF
SETLOCAL enabledelayedexpansion
SET "br=^<br^>"
SET "hr=^<hr^>"
SET "h1=^<h1^>"
SET "sh1=^</h1^>"
SET "bold=^<b^>"
SET "sbold=^</b^>"
(
FOR /f "delims=" %%i IN ('type news.txt^|findstr /n "$"') DO (
SET line=%%i&CALL :process
)
)>news.html
GOTO :eof
:process
:: remove line number from line
SET "line=%line:*:=%"
IF NOT DEFINED line ECHO(%br%&GOTO :EOF
SET "line2=%line:"=_%"
SET "line3=%line:"=%"
IF NOT "%line2%"=="%line3%" GOTO rawout
IF "%line%"=="===" ECHO(%hr%&GOTO :EOF
IF "%line:~0,5%"=="Date:" ECHO(%bold%%line%%sbold%&GOTO :EOF
IF "%line:~0,2%%line:~-2%"=="****" ECHO(%h1%%line:~2,-2%%sh1%&GOTO :EOF
:rawout
ECHO(!line!%br%
GOTO :eof
这应该适合你。它对每一行进行编号,然后将编号的行分配给line
. 这是一种常用技术,因为for /f
会跳过空行。
:process
仅查找密钥字符串并输出适当的替换。
我使用了检测“开始和结束”的快捷方式“**” . There are more reliable ways of doing it - but it should only fail if the line is
*** or
**` - 如果有问题,相对容易修复......
(编辑 20130531-0134Z 新:process
程序以更改规范)
{重新编辑 20130531-0750Z 将 enableelayedexpansion 添加到 setlocal 和 echo !line!在 :rawout 之后以适应不平衡引号}