Parse Text File, Trim Strang and Left of String

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DillonFoulds
Posts: 1
Joined: 05 May 2021, 19:18

Parse Text File, Trim Strang and Left of String

Post by DillonFoulds » 05 May 2021, 19:32

I've got a log file (Minecraft's "latest.log") that has a line of (player generated via in-game chat):

Code: Select all

\\\ Begin File - latest.log
... <truncated>
[17:56:14] [Server thread/INFO]: <Playername0> !seed <valuable text string>
... <truncated>
\\\ End File
What I would like to do is parse the log file for any line containing "!seed" and dump it to a new file...

Currently this is accomplished via a batch using "findstr /i "!seed" logs\latest.log > NewSeed.txt"

Which returns the valuable line to a new file.

Code: Select all

\\\ Begin File - NewSeed.txt
[17:56:14] [Server thread/INFO]: <Playername0> !seed <valuable text string>
\\\ End File
The next step I'm hoping to accomplish is to read only the <valuable text string> portion, ie: everything after "!seed ", including the trailing space.

Once that's output to a file/variable I'd like to write it to server.properties (IniWrite probably can accomplish this?) and finish processing my server files accordingly.

All I need is the syntax to parse that NewSeed.txt to trim everything "!seed " and left, OR read only everything after "!seed ".

Any tips? RegEx?
User avatar
mikeyww
Posts: 26592
Joined: 09 Sep 2014, 18:38

Re: Parse Text File, Trim Strang and Left of String

Post by mikeyww » 05 May 2021, 21:35

Code: Select all

str =
(
\\\ Begin File - latest.log
... <truncated>
[17:56:14] [Server thread/INFO]: <Playername0> !seed <valuable text string1>
aa
[17:57:14] [Server thread/INFO]: <Playername0> !seed <valuable text string2>
bb
[17:58:14] [Server thread/INFO]: <Playername0> !seed <valuable text string3>
... <truncated>
\\\ End File
)
FileRecycle, % log := A_ScriptDir "\seed.log"
FileAppend, % strings(str), %log%
Run, %log%

strings(str) {
 For lineNum, line in StrSplit(str, "`n")
  RegExMatch(line, "!seed\K.+", val), ttext .= val > "" ? "`n" val : ""
 Return SubStr(ttext, 2)
}
Post Reply

Return to “Ask for Help (v1)”