How to extract paragaph and selected lines with Perl

Posted by neversaint on Stack Overflow See other posts from Stack Overflow or by neversaint
Published on 2010-04-14T10:40:22Z Indexed on 2010/04/14 10:43 UTC
Read the original article Hit count: 350

Filed under:
|
|
|

I have a text that looks like this. What I want to do is

  1. to extract the whole paragraph under the section "Aceview summary" until the line that starts with "Please quote".
  2. extract the line that starts with "The closest human gene".

And store them into array with two elements.

However I am stuck with the following script logic. What's the right way to achieve that?

   #!/usr/bin/perl -w

   my  $INFILE_file_name = $file;      # input file name

    open ( INFILE, '<', $INFILE_file_name )
        or croak "$0 : failed to open input file $INFILE_file_name : $!\n";


    my @allsum;

    while ( <INFILE> ) {
        chomp;

        my $line = $_;

        my @temp1 = ();
        if ( $line =~ /^ AceView summary/ ) {
            print "$line\n";
            push @temp1, $line;
        }
        elsif( $line =~ /Please quote/) {
            push @allsum, [@temp1];
             @temp1 = ();
        }

    }

    close ( INFILE );           # close input file

© Stack Overflow or respective owner

Related posts about perl

Related posts about unix