[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Positioning a new lua distribution
- From: Bennett Todd <bet@...>
- Date: Fri, 28 Feb 2003 11:12:25 -0500
2003-02-27T14:48:40 Kurt Jung:
> >The virtue of awk is the implicit input and pattern-action syntax,
> >but that can also make it clumsy in some circumstances.
>
> Perhaps we could revamp the lua standalone to accept a command line
> argument which would put it into "awk mode". One feature of sed and
> awk that never quite seems practical with lua is the ability to do
> powerful things with a single line using the -e option.
Perhaps it might be useful to consider some of the cmdline args perl
has for making perl ... -e ... more useful. I offer this just in
case the design that seems to work well for perl also turns out to
be a good fit for Lua --- I don't know.
For awkish behavior (as well as sed -n), perl has -n, to have an
implicit read loop wrapped around the -e arg.
For sed-ish behavior, there's -p, implicit read loop w/ print at the
end.
Again awklike, there's -a for autosplit to split each input line on
whitespace, which can be overriden with -Ffieldsep to specify an
alternative field separator.
The option -l will automatically chop off the line terminator after
the read, and will automatically append one to each print; sometimes
it's easier to express the transform you want on the lines without
their terminators present.
The line terminator can be overriden with -0, and as it can take an
octal escape the idiom -0777 on the cmdline (to produce an integer
that will never be a valid byte value) means to treat the entire
input file as a single line, sometimes helpful.
Another "-e" empowering arg is "-i[ext]", for inplace editing of
files. The perl implicit loops chew over named files or stdin if
none are named. With -i and named files, the files are edited
in-place. If an ext is given to the -i arg (e.g. -i.bak is
idiomatic) the original is saved with that extension.
I think that about exhausts the ones I use routinely.
-Bennett
Attachment:
pgpZwYZNCo8V4.pgp
Description: PGP signature