lua-users home
lua-l archive

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

This little project started because I was writing a lot of little Lua
scripts to analyse logs, and getting tired of rewriting the same

The most useful operation was a kind of inverse awk: extracting fields
using string patterns:

$ echo 'your name is Frodo' | llua m '%u%l+'
$ echo 'Bonzo is a dog' | llua m '(%S+) is a (%S+)'
Bonzo dog

If you go with 'sudo lua install <dir>' then it will also create an
alias 'lmatch' for this operation - like BusyBox, it creates a little
collection of utilities that do different things depending on the
symbolic link

$ mount | lmatch '(/dev/%S+) on (%S+)'
/dev/sda2 /
/dev/sdb1 /home

Lua string.gsub is also useful - exposed as lsub

$ echo 'bonzo is a dog' | lsub '(%S+) is a (%S+)' '%2-%1'

$ lsub -t 'HOME is where the heart is'  -l '(%u+)' 'getenv(s)'
/home/steve is where the heart is

The second form uses a function of 's' for the substitution; anything
in math or os is regarded to be in _G.

All these toollets work on a file or standard input, except for 'lx'
which is a souped-up 'expr'.  Numeric output can be controlled by the
environment variable LLUA_FMT - in fact I implicitly use '%g' when
running Lua 5.3 to prevent the irritating display of 1 as 1.0, etc.

Now obviously it scratches my itch - I know Lua string patterns well.
Not sure how someone who wasn't familiar with this notation, although
I suppose users of standard regular expressions can do the mental

steve d.

PS Yes, I know, I'm supposed to be releasing a new version of LDoc.
Consider this displacement activity while working on a very stressful