找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 19720|回复: 6

[日期时间] 求助批处理解析TXT文本里的时间并计算成分钟数

[复制链接]
发表于 2023-11-1 16:13:10 | 显示全部楼层 |阅读模式
本帖最后由 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
发表于 2023-11-1 16:34:16 | 显示全部楼层
很丑很不严谨
  1. $txt = gc .\a.txt; ((Get-Date (($txt | select -Last 1) -split ' ')[0])-(Get-Date (($txt | select -First 1) -split ' ')[0])).TotalMinutes
复制代码
发表于 2023-11-1 16:48:34 | 显示全部楼层
回复 1# smtcao008


    请把txt文件上传到网盘,以便测试代码,直接发出来文本内容在格式上可能会有变化。
 楼主| 发表于 2023-11-1 16:56:12 | 显示全部楼层
回复 2# wanghan519

我临时还使用最简陋的指令抓loop数先管控!~~~
 楼主| 发表于 2023-11-1 17:04:04 | 显示全部楼层
回复 3# Batcher


    已更新网盘
发表于 2023-11-1 19:23:45 | 显示全部楼层
本帖最后由 Five66 于 2023-11-2 01:28 编辑

改了下,文件名换成了网盘文件的3d.log(不是1楼的3d.txt)
分钟结果保留了4位小数,只要时间都是2位数字的,并且都符合格式的,1天之内应该也许大概都没问题?(不包括1天)

  1. @echo off

  2. set "file=3d.log"

  3. for /f "tokens=1 delims= " %%a in ('findstr /b "[0-9]" "%file%"') do (
  4. if not defined first set first=%%a
  5. set last=%%a
  6. )

  7. setlocal enabledelayedexpansion
  8. for /f "tokens=1-3 delims=:" %%a in ("!first!") do set /a m=1%%a*3600+1%%b*60+1%%c
  9. for /f "tokens=1-3 delims=:" %%a in ("!last!") do set /a n=1%%a*3600+1%%b*60+1%%c
  10. set /a "t1=n-m"
  11. if !t1! lss 0 (
  12. set /a t1=24*3600+t1
  13. )
  14. set /a t2=t1%%60
  15. set /a "t1=(t1-t2)/60"
  16. set /a t=t2*10000/60
  17. set t=0000!t!
  18. echo,time: !t1!.!t:~-4! mins
  19. endlocal

  20. pause
复制代码
发表于 2023-11-2 08:45:58 | 显示全部楼层
回复 1# smtcao008

以下是用第3方工具gawk(http://bcn.bathome.net/tool/4.1.0/gawk.exe)的实现方式

命令行方式(单百分号%)

  1. 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脚本方式(双百分号%%)

  1. 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
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-18 09:18 , Processed in 0.018799 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表