Unix Programming - sed command backreference question

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > February 2005 > sed command backreference question





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author sed command backreference question
Braveheart

2005-02-24, 5:58 pm

Hello,

I would like to execute another command from within the sed command,
similar to the following (this is just an example of what I want to
do):

echo $LIST | head -30 | sed "s/\(.*\)~\(.*\)~\(.*\)/`ls \2`/"

This doesn't work because the backreference is not expanded in the `ls
\2` section. Is there any way to do this?

Thanks!

John W. Krahn

2005-02-25, 2:51 am

Braveheart wrote:
>
> I would like to execute another command from within the sed command,
> similar to the following (this is just an example of what I want to
> do):
>
> echo $LIST | head -30 | sed "s/\(.*\)~\(.*\)~\(.*\)/`ls \2`/"
>
> This doesn't work because the backreference is not expanded in the `ls
> \2` section. Is there any way to do this?


echo $LIST | head -30 | PERL -pe's/(.*~(.*)~.*)/-e $2 ? $2 : $1/e'


John
--
use Perl;
program
fulfillment
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com