[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-recutils] Value Expressions
From: |
John Darrington |
Subject: |
Re: [bug-recutils] Value Expressions |
Date: |
Thu, 23 Aug 2012 12:30:14 +0000 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
I hadn't really thought about the syntax, but your proposoal seems reasonable.
Some hypotheitical use cases that I can think of are:
# Add a field for a person's retirement date.
recset -e 'Gender = Male' -f Retires -a '/date-of-birth + 65 years'
recset -e 'Gender = Female' -f Retires -a '/date-of-birth + 55 years'
# Add an a second email address to all those who work at foo.com
recset -e 'Email[0] = "address@hidden"' -f Email -a
'/Email[0]/s/@foo.com/address@hidden/'
This implies that any FEX element (but not a complete FEX) can be the subject
of a VEX
but we don't know if the element 0 is the one where the target is, so we need
some
kind of positional parameter:
recset -e '\(Email\) ~ "address@hidden"' -f Email -a
'/\1/s/@foo.com/address@hidden/'
Here, the \1 represents the first field in the -e expression enclosed in ()
So a more complex example:
recset -e '#(first-name)' -e '#(last-name)' -e '#(company)' -f Email -a
'address@hidden'
I can think of more complex cases; One might want to add field/value based upon
the result of a join.
- But perhaps I shouldn't go there yet.
J'
On Tue, Aug 21, 2012 at 03:50:50PM +0200, Jose E. Marchesi wrote:
Hi John.
I think it would be a good idea if the recset and recins commands could
accept some kind of "value expression" in their -s, -a and -v options.
That is to say, whereas currently only literal strings can be given
(eg:
recset -f FEX -v "value") it would be nice to allow one to have
recset -f FEX -v VEX
For example one might wish to add a new string field which is based
upon
another (existing) field: recset -f "field-new" -a
"[field-existing]s/foo/bar"
Or in the case of numeric fields: recset -f "field-new" -a
"[field-existing] + 1"
I like the idea, but what is not clear to me is which syntax to use for
the expressions.
We could generalize the usage of sed expression syntax, including the p
(print) operator, which would be the default. Examples:
Simple behaviour with fixed strings:
recset -f field-new -a foobar
Usage of sed-like syntax for expressions:
recset -f field-new -a "/field-existing + 1/p"
But then 'p' is the default operation, so:
recset -f field-new -a "/field-existing + 1/"
Substitution:
recset -f field-new -a "/field-existing/s/foo/bar/"
Something like that... ideas?
--
Jose E. Marchesi http://www.jemarch.net
GNU Project http://www.gnu.org
--
PGP Public key ID: 1024D/2DE827B3
fingerprint = 8797 A26D 0854 2EAB 0285 A290 8A67 719C 2DE8 27B3
See http://keys.gnupg.net or any PGP keyserver for public key.
signature.asc
Description: Digital signature