Afficher un message
Vieux 03/09/2007, 03h28   #6
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: selecting text between two patterns

gin_g wrote:
> Hey... I'm trying to extract text between two patterns. Ideally,
> if I had two patterns:
> PATTERN1
> PATTERN2
> I'd like to get back the text that is between the first occurance of
> those patterns, not including the patterns
> For instance, if I had the text:
>
> this is one line
> this is PATTERN1 another line
> hello
> this is somethingPATTERN2 else
> this is the last line
>
> I would want this result
>
> another line
> hello
> this is something
>
> Or if I had this text:
> this PATTERN1is one big line. But it isPATTERN2 not very long.
>
> I would want this result:
> is one big line. But it is
>
>
> Thanks!
>


With an awk that supports REs as Record Separators (e.g. gawk), it might
be just:

awk -v RS="PATTERN1|PATTERN2" 'NR==2' file

depending on whether or not PATTERN1 or PATTERN2 can occur before
PATTERN1 in your real input.

Regards,

Ed.
  Réponse avec citation
 
Page generated in 0,05518 seconds with 9 queries