Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Working with group of lines
#1
I have a file with hundred of lines. They are grouped similar to the example below.

What would be the best approach to move or copy the line that starts with the string "aaaaaa" to the beginning of every line of its group ?
The group ends at the line before the next "aaaaaa".

Input file:
aaaaaa 1
bbbbbb
...
zzzzzz

aaaaaa 2
bbbbb
...
zzzzzz

Desired output:
aaaaaa 1 aaaaaa 1
aaaaaa 1 bbbbbb
aaaaaa 1 ...
aaaaaa 1 zzzzzz

aaaaaa 2 aaaaaa 2
aaaaaa 2 bbbbbb
aaaaaa 2 ...
aaaaaa 2 zzzzzz
Reply


Messages In This Thread
Working with group of lines - by knob - May-21-2024, 03:29 AM
RE: Working with group of lines - by Gribouillis - May-21-2024, 07:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 6,366 Aug-10-2020, 11:01 PM
Last Post: medatib531
  retrieve group of lines knob 1 1,641 Oct-28-2019, 07:02 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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