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
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!