From: Rob Lee <[EMAIL PROTECTED]> > I'm parsing a file with multiple Fortran-like blocks that look like: > START_KEYWORD > line 1 > line 2 > END_KEYWORD > > I want only the contents of each block, not the keywords. > > grep { /START_KEYWORD/.../END_KEYWORD/ } > returns the entire block - including the start and end keywords. > > Is there a slick way to only return the contents of the block (line 1 > and line 2)?
This is not realy a regex question. I think you want this: grep { /START_KEYWORD/.../END_KEYWORD/ and !/START_KEYWORD/ and !/END_KEYWORD/} But if the START_KEYWORD and END_KEYWORD is supposed to be the only thing on the lines then grep {chomp $_; ($_ eq 'START_KEYWORD') ... ($_ eq 'END_KEYWORD') and !($_ eq 'START_KEYWORD') and !($_ eq 'END_KEYWORD')} would be quicker. (Notice the chomp() there. It might be unnecessary if the lines are already chomped, but keep in mind that it modifies the elements of the original array!) Jenda =========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ========== There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]