lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 24/09/2013 8:51 PM, Luiz Henrique de Figueiredo wrote:
Take the following output from a netstat command.

Client Name: SMTP                     Client Id: 000000B7
[...]
I would love to learn how to write LPeg parser to yank the key->values
from that multi-line report easily.
You don't need LPeg for this task. Try
	for k,v in T:gmatch("(%u[%w ]-):%s*(.-)%s") do print(k,v) end
where T contains the netstat output.

Thanks. This is how dumbstruck I am WRT pattern matching. I want to parse the following piece of netstat output

SKRBKDC  00000099 UDP
  Local Socket:   172.17.69.30..464
  Foreign Socket: *..*

The top line is the user, connection id and state. All I want to do is capture three whitespace seperated words.

In REXX I would do this:

parse var line userid connid state

What is the most succinct way of doing something similar in Lua?


But don't let that discourage you from learning LPeg. There is nothing
more effective for learning than concrete motivation.