passing variable to regular expression (PERL)

passing variable to regular expression (PERL)

am 07.09.2007 20:28:45 von krisworld

hi all

say I have a target file as
-----
-----
aaaa = { bbbbbbbbbbbbbbbbbbbb}
qqqq ={ dddddddddddd,
cccccccccccccc}
-------
--------
and i need output as
{ bbbbbbbbbbbbbbbbbbbb}
or
{ dddddddddddd,
cccccccccccccc} depending on aaaa or qqqq


so if i use

echo $Result |perl -lne "print if / aaaa ={ /../ }"
i get result

but i need to put it in loop

while read SOMETHING; do

echo $Result |perl -lne "print if / $SOMETHING={ /../ }"

done

I am not able to do it.
Can any one help me...
regards
kris

Re: passing variable to regular expression (PERL)

am 08.09.2007 02:05:03 von Bill Marcum

On Fri, 07 Sep 2007 18:28:45 -0000, krisworld
wrote:
>
>
> hi all
>
> say I have a target file as
> -----
> -----
> aaaa = { bbbbbbbbbbbbbbbbbbbb}
> qqqq ={ dddddddddddd,
> cccccccccccccc}
> -------
> --------
> and i need output as
> { bbbbbbbbbbbbbbbbbbbb}
> or
> { dddddddddddd,
> cccccccccccccc} depending on aaaa or qqqq
>
>
> so if i use
>
> echo $Result |perl -lne "print if / aaaa ={ /../ }"
> i get result
>
> but i need to put it in loop
>
> while read SOMETHING; do
>
> echo $Result |perl -lne "print if / $SOMETHING={ /../ }"
>
> done
>
> I am not able to do it.
> Can any one help me...
> regards
> kris
>
while read SOMETHING; do
echo "$SOMETHING" | perl...
done < file

Do you need the while read loop, or can you do the whole thing with
perl?


--
New York is real. The rest is done with mirrors.

Re: passing variable to regular expression (PERL)

am 08.09.2007 05:21:54 von krisworld

hi
i understand what u say, but my issue is how to pass a variable in a
Regular Expression

i have
aaaa
qqqq
into "SOMETHING"
now i shall loop the complete data which is in $Result SOMETHING
I shall appreciate if u could help me.
kris


and need to extract only values in between { .. } depending on the
value of

On Sep 8, 5:05 am, Bill Marcum wrote:
> On Fri, 07 Sep 2007 18:28:45 -0000, krisworld
>
>
>
> wrote:
>
> > hi all
>
> > say I have a target file as
> > -----
> > -----
> > aaaa = { bbbbbbbbbbbbbbbbbbbb}
> > qqqq ={ dddddddddddd,
> > cccccccccccccc}
> > -------
> > --------
> > and i need output as
> > { bbbbbbbbbbbbbbbbbbbb}
> > or
> > { dddddddddddd,
> > cccccccccccccc} depending on aaaa or qqqq
>
> > so if i use
>
> > echo $Result |perl -lne "print if / aaaa ={ /../ }"
> > i get result
>
> > but i need to put it in loop
>
> > while read SOMETHING; do
>
> > echo $Result |perl -lne "print if / $SOMETHING={ /../ }"
>
> > done
>
> > I am not able to do it.
> > Can any one help me...
> > regards
> > kris
>
> while read SOMETHING; do
> echo "$SOMETHING" | perl...
> done < file
>
> Do you need the while read loop, or can you do the whole thing with
> perl?
>
> --
> New York is real. The rest is done with mirrors.- Hide quoted text -
>
> - Show quoted text -

Re: passing variable to regular expression (PERL)

am 08.09.2007 05:33:16 von Barry Margolin

In article <1189189725.076359.21350@19g2000hsx.googlegroups.com>,
krisworld wrote:

> while read SOMETHING; do
>
> echo $Result |perl -lne "print if / $SOMETHING={ /../ }"

Aren't you missing a / at the end?

>
> done
>
> I am not able to do it.
> Can any one help me...
> regards
> kris

while read SOMETHING; do
export SOMETHING
echo $Result | perl -lne 'print if / $ENV{SOMETHING}={ / .. / }/'

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***