LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   selecting few lines in perl (https://www.linuxquestions.org/questions/linux-newbie-8/selecting-few-lines-in-perl-734177/)

vinaytp 06-19-2009 08:24 AM

selecting few lines in perl
 
hi all....

In a file following are the contents........

(
etc,
ls,
/sbin/usr
.....
...
...
)
command
dksal
.......

I know how to match a pattern in a single line and get it in $1 but
here i want to select the lines between two braces ( and ) how can i accomplish this in perl

can anyone please help me.......
Thanks in advance......

bigearsbilly 06-19-2009 02:21 PM

owzthat?

Code:

#!/usr/bin/perl

local $/ = undef;  # slurp mode

$slurp = <>;    # read whole file
($lines) = ($slurp =~ /\((.*)\)/s);    #
print $lines;


ghostdog74 06-19-2009 06:21 PM

Quote:

Originally Posted by vinaytp (Post 3579595)
but
here i want to select the lines between two braces ( and ) how can i accomplish this in perl

when the line match ")", remove flag
when the line match "(" , set a flag
if flag is set, print line

Tinkster 06-19-2009 07:08 PM

Code:

while (<>) {
    print if /\(/ .. /\)/;
}


vinaytp 06-20-2009 04:31 AM

Quote:

Originally Posted by bigearsbilly (Post 3579955)
owzthat?

Code:

#!/usr/bin/perl

local $/ = undef;  # slurp mode

$slurp = <>;    # read whole file
($lines) = ($slurp =~ /\((.*)\)/s);    #
print $lines;


helped me a lot really great .......thanks a lot to everyone.......


All times are GMT -5. The time now is 01:59 AM.