Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
retrieve group of lines
#1
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
Reply
#2
As they say: 'no effort no help'
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 5,878 Aug-10-2020, 11:01 PM
Last Post: medatib531

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020