arthur99 has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I have a file that is something like this:
2008-10-01 message 1 2008-10-02 message 2 2008-10-03 multi-line message message 3 keyword 2008-10-04 message 4 2008-10-05 multi-line blah blah message 5 keyword junk 2008-10-06 message 6 blah keyword 2008-10-06 this is message 7
I want to grab all message lines that contain "keyword":
2008-10-03 multi-line message message 3 keyword 2008-10-05 multi-line blah blah message 5 keyword junk 2008-10-06 message 6 blah keyword
I tried adding the /m and /s modifiers to my regex but I couldn't get it working. I'm a perl newbie, so I must have botched something in my regex.
undef $/; while ( /^(\d+-\d+-\d+.*?keyword)(?!\d+-\d+)$/smg ) { print "$1\n"; }
Thanks,
Arthur
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: matching keyword in multi-line records
by JavaFan (Canon) on Oct 20, 2008 at 20:58 UTC | |
|
Re: matching keyword in multi-line records
by moritz (Cardinal) on Oct 20, 2008 at 20:49 UTC | |
|
Re: matching keyword in multi-line records
by billward (Initiate) on Oct 20, 2008 at 23:29 UTC | |
|
Re: matching keyword in multi-line records (slurp--)
by tye (Sage) on Oct 21, 2008 at 02:13 UTC | |
by arthur99 (Initiate) on Oct 21, 2008 at 04:09 UTC | |
|
Re: matching keyword in multi-line records
by graff (Chancellor) on Oct 21, 2008 at 01:33 UTC |