Rudra
Rudra

Reputation: 21

Searching lines after a particular line in perl

I have a logfile and there I am trying to store all the line once I found This has happened due to. and then new line starts.

So basically the log looks like this

Bla bla bla bla....This has happened due to.

ABC

DEF

GHI

JKL

can you please help me to match the paatern once I found the line "This has happened due to."

Upvotes: 1

Views: 94

Answers (2)

Barmar
Barmar

Reputation: 782653

while (<>) {
  next unless /This has happened due to/;
  while (<>) {
    # Process lines
  }
  last;
}

Upvotes: 4

Eugene Yarmash
Eugene Yarmash

Reputation: 150178

#!/usr/bin/env perl

while (<>) {
    last if /This has happened due to/;
}

while (<>) {
    print; # do smth with the line
}

Save the script to a file and make it executable. Then run like ./script.pl logfile

Upvotes: 3

Related Questions