我有一个包含许多文本文件的文件夹。这些文本文件包含以下信息:
Entity Details
Camera XYZ 31 RTP packet(s) have been lost
Camera YYZ 141 RTP packet(s) have been lost
Camera YYY 3 RTP packet(s) have been lost
Camera YYY 100 RTP packet(s) have been lost
我希望做到以下几点:
1)运行批处理文件,计算“X RTP数据包丢失”的总数
2)运行批处理文件,该文件将计算每个实体的“X RTP数据包丢失”的总数。 (例如,相机YYY = 103 RTP数据包丢失)
任何帮助都会很棒!
答案 0 :(得分:0)
当我等待您回答评论中的问题时,如果您可以使用PowerShell版本,请点击此处:
gc *.txt | ?{$_ -match 'lost'} | %{
$null = $_ -match '\s+(.+?)\s{2,}(\d+)'
New-Object PSObject -Prop @{ Entity = $Matches[1]; Count = [int]$Matches[2]}
} | group Entity | %{
"$($_.Name) = $(($_.Group | select -exp Count | measure -sum).Sum) RTP packets lost"
}
批处理文件中的问题要复杂得多,因此存在问题。
答案 1 :(得分:0)
假设
XYZ
,YYZ
,YYY
等是单个字,
有问题的值始终是该行的第三个“字”,
将相同的实体组合在一起,
@ECHO OFF
FOR %%F IN (D:\Path\To\Files\*.txt) DO (
SET camera=
SET totalcnt=0
FOR /F "tokens=2,3" %%A IN (%%F) DO CALL :process %%A %%B
CALL :process "" 0
CALL ECHO Total for file %%F: %%totalcnt%%
)
GOTO :EOF
:process
IF "%camera%" == "%1" GOTO continue
IF NOT "%camera%" == "" ECHO Total RTP packets for Camera %camera%: %cnt%
SET cnt=0
SET camera=%1
:continue
SET /A cnt+=%2
SET /A totalcnt+=%2