Python Forum

Full Version: retrieve group of lines
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Good evening !
Would be possible to read a file (around 80k lines) and every time the word XYZ appears,
the code would retrieve this line, and all next lines up to the next empty line, aligning the results ?

This would be the input :
asda
asdada
XYZ asdasda           <=should be retrieved 
  adsada              <=should be retrieved 

adadas
adsada
asdada

XYZ asdasda           <=should be retrieved 
  adsada              <=should be retrieved 
  adsada              <=should be retrieved 

adada
adadad
This would be the output:
XYZ asdasda adsada                     <=first group retrieved aligned

XYZ asdasda adsada adsada              <=second group retrieved aligned
As they say: 'no effort no help'