试试这个批处理文件。添加日志文件名作为参数。例如:
LISTTAG.BAT SOH.LOG
它将显示所有标签 ID 及其唯一值。例如:
9=387
12=abc
34=asb73
9=123
12=xyz
命名的文件tagNNlist.txt
(其中NN
是标签 ID 号)将用于查找唯一的标签 ID 和值,但在批次结束时作为报告保持不变。
{SOH}
下面代码中显示的文本实际上是SOH字符(ASCII 0x01),所以复制粘贴代码后,应该将其更改为SOH字符。我必须替换该字符,因为它已被服务器剥离。使用写字板通过键入生成SOH字符,0001
然后按ALT+X
。使用批处理文件代码将该字符复制并粘贴到记事本中。
需要注意的一件事是,代码只会处理从第 16 列开始的行。07:00:32 -SEND:
示例中的行将被忽略。我假设它们都以固定长度的文本开头。
变化:
LISTTAG.BAT
:
@echo off
setlocal enabledelayedexpansion
if "%~1" == "" (
echo No source file specified.
goto :eof
)
if not exist "%~1" (
echo Source file not found.
goto :eof
)
echo Warning! All "tagNNlist.txt" file in current
echo directory will be deleted and overwritten.
echo Note: The "NN" is tag id number 0-99. e.g.: "tag99list.txt"
pause
echo.
for /l %%a in (0,1,99) do if exist tag%%alist.txt del tag%%alist.txt
for /f "usebackq delims=" %%a in ("%~1") do (
rem *****below two lines strip the first 15 characters (up to "-SEND:")
set x=%%a
set x=!x:~15,99!
rem *****9 tags per line
for /f "tokens=1,2,3,4,5,6,7,8,9 delims={SOH}" %%b in ("!x!") do (
call :dotag "%%b" %*
call :dotag "%%c"
call :dotag "%%d"
call :dotag "%%e"
call :dotag "%%f"
call :dotag "%%g"
call :dotag "%%h"
call :dotag "%%i"
call :dotag "%%j"
)
)
echo.
echo Done.
goto :eof
rem dotag "{id=value}"
:dotag
for /f "tokens=1,2 delims==" %%p in (%1) do (
set z=0
if exist tag%%plist.txt (
call :chktag %%p "%%q"
) else (
rem>tag%%plist.txt
)
if !z! == 0 (
echo %%q>>tag%%plist.txt
echo %~1
)
)
goto :eof
rem chktag {id} "{value}"
:chktag
for /f "delims=" %%y in (tag%1%list.txt) do (
if /i "%%y" == %2 (
set z=1
goto :eof
)
)
goto :eof