Thanks for these explanations. They confirm what I suspected.
Assuming that the number of lines in one group can never exceed, say, 15 or 
so, could one circumvent the difficulty by explicitly repeating the search 
pattern a sufficient number of times? 
Then the problem would be to ensure a match also in the case when the 
number of lines is smaller. Any idea on how that could be achieved? Could 
conditional matching help (I am not familiar with those "advanced 
features")?

Le vendredi 5 octobre 2012 20:01:21 UTC+2, Patrick Woolsey a écrit :
>
> At 08:18 -0700 10/05/2012, jmichel wrote: 
> >I have a file consisting of groups of lines (unknown number of lines in 
> >each group). 
> >Each line begins by a 6 digit number, followed by an unknown sequence of 
> >words and numbers. 
> >Consecutive lines starting with the same number form a group. 
> >My problem is to combine lines from each group into a single line, 
> keeping 
> >only the first occurrence of the distinctive number. 
> >I have been able to "find" groups using the pattern 
> >(\d{6})(.+)(?:\r\1(.+))+ 
> > 
> >However, this does not appear to store the expressions matching the inner 
> >parentheses into separate variables. 
> > 
> >Is there a way to achieve the desired replacement using grep? 
>
>
> Provided I understand the task correctly, though your pattern should match 
> all such groups of lines, I don't see any way to restructure the matched 
> text in a single step. 
>
> (A relatively easy brute force solution would be to concatenate all 
> matching line pairs, then rinse & repeat. :) 
>
> As to your question about storage: 
>
> Though the contents of that inner subpattern (.+) are being captured N 
> times (where N is the number of lines within the match), only the last 
> instance matched will be stored and available by reference to that 
> subpattern. 
>
>    [ As an aside for anyone else who may be wondering, this part of 
>      the pattern (?: ) consists of `non-capturing parentheses` which 
>      do not themselves store matched text. ] 
>
> For example, if you apply the following search & replace patterns: 
>
> Find:      (?:(\d{6})\r)+ 
> Replace:   \1 
>
> to this text: 
>
> 111222 
> 333444 
> 555666 
>
> the result will be: 
>
> 555666 
>
>
> Regards, 
>
>  Patrick Woolsey 
> == 
> Bare Bones Software, Inc.             <http://www.barebones.com/> 
>

-- 
-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, 
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>



Reply via email to