Parse a log file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
brandon079
Posts: 2
Joined: 01 Oct 2012 16:33

Parse a log file

#1 Post by brandon079 » 01 Oct 2012 16:37

I have a log file that looks like:

c:/logs/log.log

Code: Select all

[10-01-2012 17:35:07] TPS: 20.0  Memory free: 16439.0/18204.0
Players online: 7
[10-01-2012 17:40:07] TPS: 20.0  Memory free: 17127.0/18204.0
Players online: 6
[10-01-2012 17:45:08] TPS: 19.3  Memory free: 17042.0/18204.0
Players online: 5
[10-01-2012 17:50:08] TPS: 20.0  Memory free: 16919.0/18204.0
Players online: 5
[10-01-2012 17:55:08] TPS: 19.3  Memory free: 16950.0/18204.0
Players online: 8
[10-01-2012 18:00:08] TPS: 19.3  Memory free: 16430.0/18204.0
Players online: 8
[10-01-2012 18:05:08] TPS: 20.0  Memory free: 16112.0/18204.0
Players online: 9
[10-01-2012 18:10:08] TPS: 20.0  Memory free: 16568.0/18204.0
Players online: 10
[10-01-2012 18:15:11] TPS: 19.3  Memory free: 15496.0/18204.0
Players online: 12
[10-01-2012 18:20:11] TPS: 20.0  Memory free: 16136.0/18204.0
Players online: 12
[10-01-2012 18:25:15] TPS: 20.0  Memory free: 15615.0/18204.0
Players online: 12
[10-01-2012 18:30:15] TPS: 19.3  Memory free: 15797.0/18204.0
Players online: 12
[10-01-2012 18:35:15] TPS: 20.0  Memory free: 15445.0/18204.0
Players online: 11



I am needing to pull the last TPS and Players Online values into separate variables. Can anyone help?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Parse a log file

#2 Post by foxidrive » 01 Oct 2012 16:46

Code: Select all

@echo off
set file="c:\logs\log.log"
for /f "tokens=3" %%a in ('find /i "players" ^<%file%') do set players=%%a
for /f "tokens=4" %%a in ('find /i "TPS:" ^<%file%') do set TPS=%%a
echo players="%players%"
echo tps="%tps%"
pause

brandon079
Posts: 2
Joined: 01 Oct 2012 16:33

Re: Parse a log file

#3 Post by brandon079 » 01 Oct 2012 17:14

@foxdrive You are awesome! This worked perfectly. For those curious what this allowed me to accomplish is to track our Minecraft server TPS (ticks per second) and player count by having a batch file export xml data it's parsed thus allowing me to track performance history via PRTG.

Post Reply