Script Help

Post Reply
Mani
Posts: 1
Joined: Mon Mar 01, 2010 6:59 am

Script Help

Post by Mani »

Hullo,

Looking to write a script that will capture the name/number on 6 logs, then add up each number and tell me the total for each name in said logs. It appears as :

--Activity Summary--
Name 1: 50
Name 2: 65
Name 3: 12

and so on. So, hypothetically, I'd set an alias to go through all six logs, then my script would add up all these numbers from the 6 logs and tell me the totals. The names will be dynamic. I'm tired, so the explanation of what I want may be vague - please post if you need some clarification.

Thank you!

Denarii
Posts: 111
Joined: Thu Dec 03, 2009 10:54 pm

Re: Script Help

Post by Denarii »

Code: Select all

^logtotal ([A-Z]:\\[^/:\*\?<>\|]+\.\w{2,6})|(\\{2}[^/:\*\?<>\|]+\.\w{2,6})(?: ([A-Z]:\\[^/:\*\?<>\|]+\.\w{2,6})|(\\{2}[^/:\*\?<>\|]+\.\w{2,6}))+$
Code: [show] | [select all] lua
local logs = { unpack( matches, 2 ) }
local patt = rex.new[[^\w+: (\d+)$]]
local total = 0

for _, log in ipairs( logs ) do
	local cur_log_amt = 0
	for line in io.lines( log ) do
		local amt = patt:match( line )
		total = total + amt
		cur_log_amt = cur_log_amt + amt
	end
	echo( log .. ": " .. cur_log_amt )
end

echo( "Total: " .. total )
logtotal path1 path2 ... pathn

Each has to be a full, valid path, e.g. C:\Users\User\Documents\mudlet\log.txt

Post Reply