Split a file into 16 small files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split a file into 16 small files
# 1  
Old 06-17-2008
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  
Old 06-17-2008
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  
Old 06-17-2008
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  
Old 06-17-2008
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  
Old 06-17-2008
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  
Old 06-17-2008
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  
Old 06-17-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Split large file into 24 small files on one hour basis

I Have a large file with 24hrs log in the below format.i need to split the large file in to 24 small files on one hour based.i.e ex:from 09:55 to 10:55,10:55-11:55 can any one help me on this.! ... (20 Replies)
Discussion started by: Raghuram717
20 Replies

2. Shell Programming and Scripting

Breaking large file into small files

Dear all, I have huge txt file with the input files for some setup_code. However for running my setup_code, I require txt files with maximum of 1000 input files Please help me in suggesting way to break down this big txt file to small txt file of 1000 entries only. thanks and Greetings, Emily (12 Replies)
Discussion started by: emily
12 Replies

3. Shell Programming and Scripting

How to split this txt file into small files?

Dear shell experts, I would like to spilt a txt file into small ones. However, I did not know how to program use shell. If someone could help, it is greatly appreciated! Specifically, I supposed there is file named A.txt. The content of the file likes this: Subject run condtion ACC time... (3 Replies)
Discussion started by: psychmyluo
3 Replies

4. Shell Programming and Scripting

Split a large array into small chunks

Hi, I need to split a large array "@sharedArray" into 10 small arrays. The arrays should be like @sharedArray1,@sharedArray2,@sharedArray3...so on.. Can anyone help me with the logic to do so :(:confused: (6 Replies)
Discussion started by: rkrish
6 Replies

5. Solaris

How to split 10GB file into small Sizes

Hi Team I have one 10 Gb log file I want to split it into say 10 of 1-1Gb file pls share ur experiences how to do this? Thanks in advance, (3 Replies)
Discussion started by: zimmyyash
3 Replies

6. UNIX for Advanced & Expert Users

Splitting a file into small files

Hi Folks, Please help me in solving the problem. I want to write script in order to split a file into small pieces and send it automatically through mail. Ex. The file name is CALM*.txt . It is around 50 MB. I want to split the file into 20 MB 2-3 smaller files and send (like uuencode) it... (6 Replies)
Discussion started by: piyushbhashkar
6 Replies

7. UNIX for Dummies Questions & Answers

How to split a huge file into small pieces (per 2000 columns)?

Dear all, I have a big file:2879(rows)x400,170 (columns) like below. I 'd like to split the file into small pieces:2879(rows)x2000(columns) per file (the last small piece will be 2879x170. So far, I only know how to create one samll piece at one time. But actually I need to repeat this work... (6 Replies)
Discussion started by: forevertl
6 Replies

8. Shell Programming and Scripting

script to splite large file to number of small files

Dear All, Could you please help me to split a file contain around 240,000,000 line to 4 files all equally likely , note that we need to maintain that the end of each file should started by start flage (MSISDN) and ended by end flag (End), also the number of the line between the... (10 Replies)
Discussion started by: ahmed.gad
10 Replies

9. Shell Programming and Scripting

Split large file and add header and footer to each small files

I have one large file, after every 200 line i have to split the file and the add header and footer to each small file? It is possible to add different header and footer to each file? (7 Replies)
Discussion started by: ashish4422
7 Replies

10. Shell Programming and Scripting

Splitting large file into small files

Hi, I need to split a large file into small files based on a string. At different palces in the large I have the string ^Job. I need to split the file into different files starting from ^Job to the last character before the next ^Job. Also all the small files should be automatically named.... (4 Replies)
Discussion started by: dncs
4 Replies
Login or Register to Ask a Question