Python Forum
printing set of lines between patterns
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
printing set of lines between patterns
#1
I have a requirement were in i need to print the lines between 2 patterns into files 
The text in the below format is available in a file. The requirement is to create a new file for each "StartPattern" and write the lines after it into the file till the "EndPattern" is reached. The StartPattern names change but the EndPattern is a constant string.  I'm new to python so unable to get a complete program to do it

<StartPattern1>
line1
line2
line3
line4
<EndPattern>

<StartPattern2>
line1
line2
line3
<EndPattern>

....
....
....

Example Output
============

1. StartPattern1.txt
2. StartPattern2.txt
Reply
#2
(Dec-13-2016, 10:22 AM)pybegin Wrote:  I'm new to python so unable to get a complete program to do it
We will still need to see an attempt and hear what exact problem you are facing before we will be able (willing) to help you.
Reply
#3
I, personally, come here to help people learn python. Not to write code. I have a day job (...and projects I work on on the weekends/nights) for that. Give it a try, and a lot of us will gladly help you figure out what you can't. But we won't start/finish it for you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Regex Include and Exclude patterns in Same Expression starzar 2 735 May-23-2023, 09:12 AM
Last Post: Gribouillis
  The included URLconf 'scribimus.urls' does not appear to have any patterns in it. nengkya 0 1,037 Mar-03-2023, 08:29 PM
Last Post: nengkya
  How to remove patterns of characters from text aaander 4 1,068 Nov-19-2022, 03:34 PM
Last Post: snippsat
  python-docx: preserve formatting when printing lines Tmagpy 4 2,005 Jul-09-2022, 01:15 AM
Last Post: Tmagpy
  Extracting data based on specific patterns in a text file K11 1 2,180 Aug-28-2020, 09:00 AM
Last Post: Gribouillis
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 5,706 Aug-10-2020, 11:01 PM
Last Post: medatib531
  Random nr. no repetition & printing multiple lines Joey 7 2,737 Feb-05-2020, 04:23 PM
Last Post: Larz60+
  How to Find & Count String Patterns Between two Markers in a HTML file ahmedwaqas92 3 2,903 Aug-19-2019, 10:12 AM
Last Post: ahmedwaqas92
  Messenger Library for MVC-like Patterns CanadaGuy 2 2,367 Nov-05-2018, 04:46 PM
Last Post: CanadaGuy
  Printing lines in a basic text file Drone4four 6 3,808 Aug-16-2018, 03:10 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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