Python Tutorial - Read data from text file and split into multiple files

preview_player
Показать описание
In previous tutorials, we have seen how to read data from json or xml file and extract meaningful information from them using python script.

Here is another problem statement where data is in text file and we want to split it into multiple text files based on some delimiter, tag or set of special characters.

Feel free to ask your queries in comment section or you may directly email to me.
Рекомендации по теме
Комментарии
Автор

THANK YOU!

I was trying to make a discord bot that would pick from a random selection of "dialogue" every time someone wrote something but I didn't just want to write that into the code itself. Your video really helped me actually understand how to get the data I wanted from a txt

mewmewpewpew
Автор

Great and simple solution. Thank you very much.

armandogomez
Автор

Very Nice work. How do I modify this code to name the file the same string located 3 lines after the delimiter. Your help is much appreciated.

minostar
Автор

Thanks a lot for this code, but i want some more examples if you can help me to solve this, Actually i want that i extract the data by choosing the id value from the sections and generate the chapter with same id value.
Kindly give me some suggestions if you have.
Thanks in advance

eshwar
Автор

Why do you use fo.read().split("\n") and not just fo.readline()? read() will read the entire document then split it by line? what is the diffference between readline(), read(), read().split() in this situation?
thank you

mariotomas
Автор

hi, do you have any tutorials on how to recombine these text files?

darylsanjuan
Автор

Your video was very helpful for me. Thank you!

tinaolfatbakhsh
Автор

Kamel, I am using .RTF How do I split whileI keeping the **** line in the text? Also is there a way to instead of using use the format of the text as the separator?

j-center
Автор

Kindly suggest the method for splitting a text file with say 1024 lines/ entries into 10 files with almost equal lines in each. That is say nine files of 103 lines and a tenth file of 97 lines. The intention is to split a file with a few thousand entries into 10 smaller files of almost equal number of entries.

rameshm
Автор

i have }, {/n in the data as the delimiter how would we get that split ? and if we wanted to do this for 10 MB of file this method would break right ?

rajeshraji
Автор

Thanks for the video, it helped me a lot.
Suppose, I've got a text file now I need to split it by a number of words i.e, 1st file would contain 1st 1000 words and 2nd files would contain next 1000 words. Can you provide some logic to implement that?

souvikdas
Автор

We have a requirement wherein we want to transfer file from one server to another. We want to check the file integrity while the file is moved from one server to another, sometimes we might also want to download in local and re-upload the same file in a server, so while doing this how to check if the file is not changed or modified.

Nexatek
Автор

How to split based on the delimiter and also on size

swathireddy
Автор

hi, how to add delimiters(in this case stars) in newly created files

someshbabu
Автор

nice video but Idk how to change the name of the files createdf to be like the frst line of each section, that would be nice

tymo
Автор

Do you perhaps know why I have no output files in my folder after running the code? No errors, just no output. Thank you!

Paula-xilx
Автор

Sir is it possible to print out one specifik word from the text file in any row? If so how can I do this?

DB-pdls
Автор

i want to delete some starting lines upto i get one word(FEATURES) in the file, SO how to do that?

shubhamkhobragade
Автор

Thank you for the video. It is very helpful. Can you let us know if the starting line had instead of how would it be i.e. if it was like:

Hello Kamal
bla bla bla

Hello Kamal
bla bla bla

Hello Kamal
bla bla bla


So basically what I'd like to see in the output is below

Hello Kamal
bla bla bla



Hello Kamal
bla bla bla

The first part and the third part.

geo
Автор

i have csv file with data i need to separate the file with python script, could you please suggest me the script

mkrishna