LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-07-2010, 03:05 PM   #1
ge_shekhar
LQ Newbie
 
Registered: Sep 2010
Posts: 16

Rep: Reputation: 0
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
 
Old 09-07-2010, 03:21 PM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
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.
 
Old 09-07-2010, 03:23 PM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

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

Hope this helps.
 
Old 09-07-2010, 03:39 PM   #4
igadoter
Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: slackware 12.2, scientific linux 6.4, knoppix 7.2, salix 14.1
Posts: 854

Rep: Reputation: 79
Always install manuals. This is the first source of information. try
Code:
man split
 
Old 09-08-2010, 01:25 AM   #5
ge_shekhar
LQ Newbie
 
Registered: Sep 2010
Posts: 16

Original Poster
Rep: Reputation: 0
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
 
Old 09-08-2010, 02:31 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
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.
 
Old 09-08-2010, 05:07 AM   #7
ge_shekhar
LQ Newbie
 
Registered: Sep 2010
Posts: 16

Original Poster
Rep: Reputation: 0
Hi,

Thanks for your valuble input. My problem is resolved.



Regards
Shekhar
 
Old 09-08-2010, 06:19 AM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
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)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MailWatch subject problen wines Linux - Server 0 08-20-2010 07:06 AM
How to open multiple files with spliting window in Emacs? cola Linux - Newbie 4 04-22-2010 01:13 AM
Spliting files th3gh05t Linux - Newbie 11 09-15-2006 05:46 AM
problen with Qt in debian sarge Waldorf Linux - Software 2 12-07-2005 03:22 AM
saving log files / spliting ethernet without a router w/ linux aarond Linux - Security 2 07-31-2004 03:34 PM


All times are GMT -5. The time now is 08:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration