The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Split large file and add header and footer to each small files ashish4422 Shell Programming and Scripting 7 07-07-2008 03:13 PM
Split A File Into 2 Files dummy_needhelp Shell Programming and Scripting 7 11-04-2007 07:36 PM
Split File into seperate files eltinator Shell Programming and Scripting 4 08-03-2007 03:27 PM
Split a file into 2 or more files bobo UNIX for Dummies Questions & Answers 4 01-16-2006 05:15 PM
Splitting large file into small files dncs Shell Programming and Scripting 4 06-08-2005 12:02 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-17-2008
rrkks rrkks is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 6
Split a file into 16 small files

Hi

I want to split a file that has 'n' number of records into 16 small files.

Can some one suggest me how to do this using Unix script?

Thanks
rrkk
  #2 (permalink)  
Old 06-17-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Have a look at "split" man page:

Code:
man split
and then, assuming n=100, 100/16=6.25 (rounded to 7):

Code:
split -7 input_file.txt
  #3 (permalink)  
Old 06-17-2008
wempy's Avatar
wempy wempy is offline
Registered User
  
 

Join Date: Jun 2006
Location: Harpenden, UK
Posts: 208
you could use the split command. Have a look at the -l (lines) and -b (bytes) parameters depending on whether your records are line delimited or size delimited.
  #4 (permalink)  
Old 06-17-2008
rrkks rrkks is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 6
hi

Hi

my file is a line delimited and am new to unix, can you give me the script how to do it.

keep in mind that every time the number of records may change but it has to be split only into 16 small file.

Thanks
rrkk
  #5 (permalink)  
Old 06-17-2008
wempy's Avatar
wempy wempy is offline
Registered User
  
 

Join Date: Jun 2006
Location: Harpenden, UK
Posts: 208
therefore the steps to take are:

1, count the number of records in the file (i.e. number of lines) - the wc utility can do this

2. divide the total number of records by 16 to get a line count for each sub file

3. use split -l <number of lines> to split the file into 16 sub files

4. optionally delete the original file

let us know if you have trouble writing these steps into a script, posting the script that you write, and we'll help further.
  #6 (permalink)  
Old 06-17-2008
rrkks rrkks is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 6
can you give me the code

Can you pls give me the Unix code as am a newb to it.

I appreciate your help.

Thanks
rrkk
  #7 (permalink)  
Old 06-17-2008
wempy's Avatar
wempy wempy is offline
Registered User
  
 

Join Date: Jun 2006
Location: Harpenden, UK
Posts: 208
I am loathe to just write the script for you, if I do you won't learn anything.

Bash Beginners Guide at tldp.org is a good starting point if you have no idea where to start.

the advanced guide is also alvailable at the same site for when you feel a little more confident.

Have a go at writing a script based on the steps I outlined above and when you get into trouble come back here and ask.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:02 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0