LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   problen in spliting files (https://www.linuxquestions.org/questions/linux-newbie-8/problen-in-spliting-files-830826/)

ge_shekhar 09-07-2010 02:05 PM

problen in spliting files
 
Hi,

I am facing a problem while spliting a text file, i need to split a file into some parts and each splited file sholld have 2000 lines, when i do it through "split" command the mother file is kept intact but as per my requirment i need to cut mother file into some parts thus it should not be kept intact .

example

file size
motherfile.txt 5000 lines.
after split
motherfile.txt 2000 lines.
childfile1.txt 2000 lines.
childfile2.txt 1000 lines.

please help.



Regards
Shekhar

slakmagik 09-07-2010 02:21 PM

The first file split produces is what you want 'motherfile.txt' to be. If you no longer want 'motherfile.txt', then just delete it. If that's not what you mean, sorry for misunderstanding and maybe you could try explaining again.

druuna 09-07-2010 02:23 PM

Hi,

Is this what you are looking for:
split -d -l 2000 motherfile.txt childfile

Hope this helps.

igadoter 09-07-2010 02:39 PM

Always install manuals. This is the first source of information. try
Code:

man split

ge_shekhar 09-08-2010 12:25 AM

Hi,

As postd in previously. as per my requirement motherfile should not be deleted but it only should be splited in some parts because my another application that contineously writes some text in motherfile.txt doesnt respond when i delete motherfile.



Regards
Shekhar

druuna 09-08-2010 01:31 AM

Hi,

You do not tell why you want to do it the way you mention and I wonder if that will give the desired result....

As you mentioned, the application keeps writing to the motherfile. If you split the motherfile itself (leave the first 2000 lines, put the rest into childfile's), new lines will be appended to the motherfiles. This will mix old and new lines and (assuming you want to do this more then once) the first 2000 lines will _always_ be the same (those "old" 2000 lines from the first split).

The solution I gave in post #3 will leave the motherfile alone. All that is in it will still be there after splitting, the content will be spread (2000 lines per file) into multiple childfile's. You could make the motherfile empty immediately after the split command (The following will make it empty without disturbing the application > motherfile.txt) so it keeps collecting and work on the childfile(s).

If the childfiles are needed later on you could give them a date stamp: split -d -l 2000 motherfile.txt childfile.$(date '+%C%Y%m%d').

Hope this helps.

Hope this helps.

ge_shekhar 09-08-2010 04:07 AM

Hi,

Thanks for your valuble input. My problem is resolved.



Regards
Shekhar

druuna 09-08-2010 05:19 AM

Hi,

Glad to see your problem is solved.

PS: Would you tag this as SOLVED (At the top of your first post: Thread Tools -> Mark as SOLVED)


All times are GMT -5. The time now is 08:27 PM.