in reply to print data between two regular expressions
But let's go ahead and blow this up:perl -ne'print if /^\[moo\]/../^\[cow\]/ and !/^\[/' log.log
Basically, the left hand side of the .. op is the delimiter you want to start printing when found, and the right hand side of the .. op is the delimiter you want to stop printing when found. Since you don't want to print the delimiters themselves, you have to add a condition to do so. I picked anything that starts with a left bracket, you will have to pick something better if your data will start with one.use strict; use warnings; open FH, '<', 'log.log' or die "can't open file\n"; print "Items found under [moo]\n"; while (<FH>) { if (/^\[moo\]/../^\[cow\]/) { print unless /^\[/; } }
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: print data between two regular expressions
by jmcnamara (Monsignor) on Oct 08, 2003 at 09:19 UTC | |
|
Re: print data between two regular expressions
by Abigail-II (Bishop) on Oct 08, 2003 at 11:10 UTC |