I have recently started learning Python3, solely trying to improve efficiency for my work. And this may be possibly an extremely basic question.
I know for strings, we can use str.split
to split the string into pieces,
according to a given character.
But how might I go for this.
With a file bigfile.txt
, some of the lines say
some intro lines xxxxxx
sdafiefisfhsaifdijsdjsia
dsafdsifdsiod
\item 12478621376321748324
sdfasfsdfafda
\item 23847328412834723
uduhfavfduhfu
sduhfhaiuesfhseuif
lots and other lines
\item 328347848732
pewprpewposdp
everthing up to and inclued this line
and the blank line too
some end lines dsahudfuha
dsfdsfdsf
What's of interest are the lines starting with \item xxxxx
and afterwards, before another \item xxxxx
How to efficiently split bigfile.txt
so I have the following:
bigfile_part1.txt
which contains
\item 12478621376321748324
sdfasfsdfafda
bigfile_part2.txt
which contains
\item 23847328412834723
uduhfavfduhfu
sduhfhaiuesfhseuif
lots and other lines
bigfile_part3.txt
which contains
\item 328347848732
pewprpewposdp
everthing up to and inclued this line
and the blank line too
ignoring the intro lines
as well as the end lines
.
Moreover, how can I apply this function to split batch files, say
bigfile2.txt
bigfile3.txt
bigfile4.txt
in exactly the same way.