标题: [日期时间] 求助批处理解析TXT文本里的时间并计算成分钟数 [打印本页]
作者: smtcao008 时间: 2023-11-1 16:13 标题: 求助批处理解析TXT文本里的时间并计算成分钟数
本帖最后由 smtcao008 于 2023-11-1 17:03 编辑
如下是3DMARK产生的3D.txt,想实现监控其跑的时间长短,理论是第一行时间和末尾行时间相减得出分钟数,这种批处理能实现吗?
13:47:34 Logging to file C:\3DMark_Logs\3DMarkLoop_01-11-2023_1347_27.log
13:47:34 _____ ____ __ __ _
13:47:34 |___ /| _ \| \/ | __ _ _ __| | __
13:47:34 |_ \| | | | |\/| |/ _` | '__| |/ /
13:47:34 ___) | |_| | | | | (_| | | | <
13:47:34 |____/|____/|_| |_|\__,_|_| |_|\_\
13:47:34 3DMark Command Line Client version: 2.6.6174 64
13:47:34 Futuremark Systeminfo version: 5.30.850.0
13:47:35 Starting benchmark. Loop 1 of inf
13:47:35 Running benchmark, system scan not included, and monitoring not included
13:47:35 Begin workload set Cloud Gate Graphics Test 1 Custom
13:48:14 End workload set Cloud Gate Graphics Test 1 Custom
13:48:14 Begin workload set Cloud Gate Graphics Test 2 Custom
13:48:56 End workload set Cloud Gate Graphics Test 2 Custom
13:48:56 Begin workload set Cloud Gate Physics Test Custom
13:49:23 End workload set Cloud Gate Physics Test Custom
13:49:23 Benchmark completed.
13:49:24 Starting benchmark. Loop 2 of inf
13:49:24 Running benchmark, system scan not included, and monitoring not included
13:49:24 Begin workload set Cloud Gate Graphics Test 1 Custom
13:50:02 End workload set Cloud Gate Graphics Test 1 Custom
13:50:02 Begin workload set Cloud Gate Graphics Test 2 Custom
13:50:45 End workload set Cloud Gate Graphics Test 2 Custom
13:50:45 Begin workload set Cloud Gate Physics Test Custom
13:51:13 End workload set Cloud Gate Physics Test Custom
13:51:13 Benchmark completed.
13:51:13 Starting benchmark. Loop 3 of inf
13:51:13 Running benchmark, system scan not included, and monitoring not included
13:51:13 Begin workload set Cloud Gate Graphics Test 1 Custom
13:51:51 End workload set Cloud Gate Graphics Test 1 Custom
13:51:51 Begin workload set Cloud Gate Graphics Test 2 Custom
13:52:34 End workload set Cloud Gate Graphics Test 2 Custom
13:52:34 Begin workload set Cloud Gate Physics Test Custom
13:53:01 End workload set Cloud Gate Physics Test Custom
13:53:01 Benchmark completed.
13:53:01 Starting benchmark. Loop 4 of inf
13:53:01 Running benchmark, system scan not included, and monitoring not included
13:53:01 Begin workload set Cloud Gate Graphics Test 1 Custom
13:53:40 End workload set Cloud Gate Graphics Test 1 Custom
13:53:40 Begin workload set Cloud Gate Graphics Test 2 Custom
13:54:23 End workload set Cloud Gate Graphics Test 2 Custom
13:54:23 Begin workload set Cloud Gate Physics Test Custom
13:54:50 End workload set Cloud Gate Physics Test Custom
13:54:50 Benchmark completed.
13:54:50 Starting benchmark. Loop 5 of inf
13:54:50 Running benchmark, system scan not included, and monitoring not included
13:54:50 Begin workload set Cloud Gate Graphics Test 1 Custom
13:55:28 End workload set Cloud Gate Graphics Test 1 Custom
13:55:28 Begin workload set Cloud Gate Graphics Test 2 Custom
13:56:11 End workload set Cloud Gate Graphics Test 2 Custom
13:56:11 Begin workload set Cloud Gate Physics Test Custom
13:56:38 End workload set Cloud Gate Physics Test Custom
13:56:38 Benchmark completed.
网盘文档已上传
链接:https://pan.baidu.com/s/1hUqCjhlsLnp44ETG_T-tzg
提取码:1234
作者: wanghan519 时间: 2023-11-1 16:34
很丑很不严谨- $txt = gc .\a.txt; ((Get-Date (($txt | select -Last 1) -split ' ')[0])-(Get-Date (($txt | select -First 1) -split ' ')[0])).TotalMinutes
复制代码
作者: Batcher 时间: 2023-11-1 16:48
回复 1# smtcao008
请把txt文件上传到网盘,以便测试代码,直接发出来文本内容在格式上可能会有变化。
作者: smtcao008 时间: 2023-11-1 16:56
回复 2# wanghan519
我临时还使用最简陋的指令抓loop数先管控!~~~
作者: smtcao008 时间: 2023-11-1 17:04
回复 3# Batcher
已更新网盘
作者: Five66 时间: 2023-11-1 19:23
本帖最后由 Five66 于 2023-11-2 01:28 编辑
改了下,文件名换成了网盘文件的3d.log(不是1楼的3d.txt)
分钟结果保留了4位小数,只要时间都是2位数字的,并且都符合格式的,1天之内应该也许大概都没问题?(不包括1天)- @echo off
-
- set "file=3d.log"
-
- for /f "tokens=1 delims= " %%a in ('findstr /b "[0-9]" "%file%"') do (
- if not defined first set first=%%a
- set last=%%a
- )
-
- setlocal enabledelayedexpansion
- for /f "tokens=1-3 delims=:" %%a in ("!first!") do set /a m=1%%a*3600+1%%b*60+1%%c
- for /f "tokens=1-3 delims=:" %%a in ("!last!") do set /a n=1%%a*3600+1%%b*60+1%%c
- set /a "t1=n-m"
- if !t1! lss 0 (
- set /a t1=24*3600+t1
- )
- set /a t2=t1%%60
- set /a "t1=(t1-t2)/60"
- set /a t=t2*10000/60
- set t=0000!t!
- echo,time: !t1!.!t:~-4! mins
- endlocal
-
- pause
复制代码
作者: hfxiang 时间: 2023-11-2 08:45
回复 1# smtcao008
以下是用第3方工具gawk(http://bcn.bathome.net/tool/4.1.0/gawk.exe)的实现方式
命令行方式(单百分号%)- gawk "$1~/([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])/{split($1,a,/:/);t2=(a[1]*60+a[2])*60+a[3];if(!r){t1=t2;r=1}}END{printf(\"hh:mm:ss %02d:%02d:%02d\",(t2-t1)/3600,(t2-t1)%3600/60,(t2-t1)%60)}" 3d.log
复制代码
bat脚本方式(双百分号%%)- gawk "$1~/([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])/{split($1,a,/:/);t2=(a[1]*60+a[2])*60+a[3];if(!r){t1=t2;r=1}}END{printf(\"hh:mm:ss %%02d:%%02d:%%02d\",(t2-t1)/3600,(t2-t1)%%3600/60,(t2-t1)%%60)}" 3d.log
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |