Python Forum
splitting file into multiple files by searching for string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
splitting file into multiple files by searching for string
#2
Look to see if the line from the file starts with (hint hint) "[Event "Let's Play!"]".
The logic would be something like this:
Output:
output file = None open input file for line in file if line starts with "[Event "Let's Play!"]" if output file close output file open new output file if output file write line to output file close input file close output file
There are also command line tools that will do the job, like awk.
Reply


Messages In This Thread
RE: splitting file into multiple files by searching for string - by deanhystad - Jul-01-2023, 11:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to generating multiple json files using python script dzgn989 4 268 May-10-2024, 03:09 PM
Last Post: deanhystad
  python convert multiple files to multiple lists MCL169 6 1,681 Nov-25-2023, 05:31 AM
Last Post: Iqratech
  Need to replace a string with a file (HTML file) tester_V 1 815 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  Splitting vocals from .wav file cfescript 1 672 May-15-2023, 09:28 PM
Last Post: Calab
  Merging multiple csv files with same X,Y,Z in each Auz_Pete 3 1,253 Feb-21-2023, 04:21 AM
Last Post: Auz_Pete
  unittest generates multiple files for each of my test case, how do I change to 1 file zsousa 0 1,001 Feb-15-2023, 05:34 PM
Last Post: zsousa
  Find duplicate files in multiple directories Pavel_47 9 3,279 Dec-27-2022, 04:47 PM
Last Post: deanhystad
  Splitting code into several files TLammert 4 1,543 Jun-26-2022, 02:33 PM
Last Post: TLammert
  Matching multiple parts in string fozz 31 6,639 Jun-13-2022, 09:38 AM
Last Post: fozz
  Extract parts of multiple log-files and put it in a dataframe hasiro 4 2,152 Apr-27-2022, 12:44 PM
Last Post: hasiro

Forum Jump:

User Panel Messages

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