[ILUG] ksh question...
Francis Daly
francisdaly at gmail.com
Thu Feb 24 21:51:37 GMT 2011
On 24/02/2011, Braun Brelin <bbrelin at gmail.com> wrote:
> On this topic, does anyone know how to capture backreferenced vars from a
> regexp?
>
> i.e. in Perl it's easy to do:
>
> ($a, $b,$c) = foo =~
> /(some_stuff_for_a)\s*(some_stuff_for_b)\s*(some_stuff_for_c)/;
>
> I can't find a good way to do this in the shell,
Not a general solution, but for this specific case "set -A bits $line"
may put useful stuff into ${bits[0]} and the like.
Otherwise, I'd probably fall back to something like multiple lines like
a=$(echo "$line" | grep -o regex_for_a)
but that's because I don't know enough ksh to be sure that there isn't
a better way.
Some languages are better suited to different tasks ;-)
f
More information about the ILUG
mailing list