www.webdeveloper.com
Results 1 to 3 of 3

Thread: Extracting a range of lines

  1. #1
    Join Date
    May 2005
    Posts
    4

    Extracting a range of lines

    I am trying to manipulate a range of lines between two patterns, "start" & "end". The two patterns can be on the same line or different line. Here are two sample blocks from the file:

    Blk1:
    start blah blah blah blah end

    or

    Blk2:
    start blah blah blah
    blah blah blah blah
    blah blah end

    I was trying to use the Perl's range operators .. or ...

    The problem is that if I use .. Blk1 does not match because the two patterns are true on the same line. But if I use ... a Blk2 following Blk1 gets mixed up because once it finds "start", it goes to the next line till it finds the "end" which causes the two blocks to get mixed up.

    Is there a way to mix the .. & ... to get what I am looking for? Or any other better way to extract a range of lines between two patterns?

    Thanks a lot!!

  2. #2
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,503
    Code:
    $bunch_of_lines =~ m/start\b(.*?)\bend/is;
    my $block_between_start_and_end = $1;
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  3. #3
    Join Date
    May 2005
    Posts
    4
    Thanks a lot Jeff. With some minor changes to your code, got it going.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles