join all lines inside pattern that occurs more than once

2007-04-26 Thread Nikolaos A. Patsopoulos

Hi,

I want to join all lines that are inside a given pattern and occurs more 
than once  in the text, ie:



PatternStart 
text1
text2
...text3
..text4
PatternEnd
...
...


PatternStart 
text1
text2
...text3
..text4
...
...textn
PatternEnd



...
PatternStart text1text2...text3..text4PatternEnd



PatternStart text1text2...text3..text4......textnPatternEnd



I tried to use:
:g/PatternStart\_.\{-}PatternEnd/ J

but this joins only first and second line of the pattern.

How can I tell vi to join all lines inside all occurrences of this 
pattern with variable containing lines?


Thanks in advance,

Nikos



Re: join all lines inside pattern that occurs more than once

2007-04-26 Thread Jürgen Krämer

Hi,

Nikolaos A. Patsopoulos wrote:
 
 I want to join all lines that are inside a given pattern and occurs more 
 than once  in the text, ie:
 
 
 PatternStart 
 text1
 text2
 ...text3
 ..text4
 PatternEnd
 ...
 ...
 
 
 PatternStart 
 text1
 text2
 ...text3
 ..text4
 ...
 ...textn
 PatternEnd
 
 
 
 ...
 PatternStart text1text2...text3..text4PatternEnd
 
 
 
 PatternStart text1text2...text3..text4......textnPatternEnd
 
 
 
 I tried to use:
 :g/PatternStart\_.\{-}PatternEnd/ J
 
 but this joins only first and second line of the pattern.
 
 How can I tell vi to join all lines inside all occurrences of this 
 pattern with variable containing lines?

the pattern you supplied only specifies a single line range. If you want
to join a whole block you must give a start address and an end address,
e.g.

  :g/PatternStart/,/PatternEnd/j

Regards,
Jürgen

-- 
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us. (Calvin)


Re: join all lines inside pattern that occurs more than once

2007-04-26 Thread Peter Palm
Op donderdag 26 april 2007, schreef Nikolaos A. Patsopoulos:
 Hi,

Hi

 I want to join all lines that are inside a given pattern and occurs
 more than once  in the text, ie:

 
 PatternStart 
 text1
 text2
 ...text3
 ..text4
 PatternEnd
 ...
 ...


 PatternStart 
 text1
 text2
 ...text3
 ..text4
 ...
 ...textn
 PatternEnd
 


 ...
 PatternStart text1text2...text3..text4PatternEnd
 
 

 PatternStart text1text2...text3..text4...   
 ...textnPatternEnd 

 I tried to use:
 :g/PatternStart\_.\{-}PatternEnd/ J

How about:

:g/PatternStart/,/PatternEnd/j


Peter