[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [ANN] lua-command-tools
- From: steve donovan <steve.j.donovan@...>
- Date: Sat, 11 Jun 2016 13:26:18 +0200
This little project started because I was writing a lot of little Lua
scripts to analyse logs, and getting tired of rewriting the same
boiler-plate.
The most useful operation was a kind of inverse awk: extracting fields
using string patterns:
$ echo 'your name is Frodo' | llua m '%u%l+'
Frodo
$ 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'
dog-bonzo
$ 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
substitution.
steve d.
https://github.com/stevedonovan/lua-command-tools
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
project.