How to make multiple small file out of a single file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to make multiple small file out of a single file?
# 1  
Old 10-18-2012
How to make multiple small file out of a single file?

Hi,

I have a file that consist of around six million line, now the task is to divide this file into 12 small file so that each file would have half a million lines in it.

Thanks.
# 2  
Old 10-18-2012
Read the man page for split.
This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 10-18-2012
Use sed

You can use sed and do it in a very nice way.

$ sed 1,500000p

or something like that.

Don't use split for straight forward line splitting.

-Girish
# 4  
Old 10-18-2012
Quote:
Originally Posted by Girish Venkatac
You can use sed and do it in a very nice way.

$ sed 1,500000p

or something like that.

Don't use split for straight forward line splitting.

-Girish
Absolutely terrible advice.

split is the perfect tool for the job. This task requires a little arithmetic and creating multiple files with unique names. split handles both. sed handles neither.

Ironically, your "straight forward" sed suggestion is seriously broken: sed 1,500000p will print the first 500000 lines twice and the next 11.5 million once.

Regards and welcome to the forum,
Alister

Last edited by alister; 10-18-2012 at 09:41 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Output file name and file contents of multiple files to a single file

I am trying to consolidate multiple information files (<hostname>.Linux.nfslist) into one file so that I can import it into Excel. I can get the file contents with cat *Linux.nfslist >> nfslist.txt. I need each line prefaced with the hostname. I am unsure how to do this. --- Post updated at... (5 Replies)
Discussion started by: Kentlee65
5 Replies

2. Shell Programming and Scripting

Script to access multiple file and operate on single file

We have three files as mentioned below: 1. main_file.txt: This is the file in which all operations will be done. Which means this file will be signed by using the below two files 2. signature_file.txt: This is a status file and contains two signatures. 3. command.txt:file contains two commands... (2 Replies)
Discussion started by: chetanojha
2 Replies

3. Shell Programming and Scripting

Multiple file and single parameter file

Hi Team, In our project we have written below 2 scripts like Script1: Shell script start & END Begin Audit process - uses teradata bteq END Audit Process Script 2: Environemtal variable file different Now Client ask to change this requirement and need below files: Script1:... (1 Reply)
Discussion started by: tusharzaware1
1 Replies

4. Shell Programming and Scripting

Execution of loop :Splitting a single file into multiple .dat file

hdr=$(cut -c1 $path$file|head -1)#extract header”H” trl=$(cut -c|path$file|tail -1)#extract trailer “T” SplitFile=$(cut -c 50-250 $path 1$newfile |sed'$/ *$//' head -1')# to trim white space and extract table name If; then # start loop if it is a header While read I #read file Do... (4 Replies)
Discussion started by: SwagatikaP1
4 Replies

5. Shell Programming and Scripting

Make multiple lines into single quoted comma separated Linux

Hi, I want to change a file file1.txt: 1234 3456 2345 6789 3456 2333 4444 As, file2.txt in Linux: '1234','3456','2345','6789','3456','2333','4444' Could someone please help me. (Single liner sed, awk will be welcome!) (7 Replies)
Discussion started by: wiweq05
7 Replies

6. Shell Programming and Scripting

Multiple File creation from Single file

I've one large file with below content TD: 0001 xxxx thnb .......... TD: 0001 yyyy abcd ......... ....... TD: 0002 xxyy efgh. ................... ................... TD: 0003 xxxx xyvx... (17 Replies)
Discussion started by: Steven77
17 Replies

7. Shell Programming and Scripting

Shell scripting - need to arrange the columns from multiple file into a single file

Hi friends please help me on below, i have 5 files like below file1 is x 10 y 20 z 15 file2 is x 100 z 245 file3 is y 78 z 23 file4 is x 100 (3 Replies)
Discussion started by: siva kumar
3 Replies

8. Shell Programming and Scripting

Awk match multiple columns in multiple lines in single file

Hi, Input 7488 7389 chr1.fa chr1.fa 3546 9887 chr5.fa chr9.fa 7387 7898 chrX.fa chr3.fa 7488 7389 chr21.fa chr3.fa 7488 7389 chr1.fa chr1.fa 3546 9887 chr9.fa chr5.fa 7898 7387 chrX.fa chr3.fa Desired Output 7488 7389 chr1.fa chr1.fa 2 3546 9887 chr5.fa chr9.fa 2... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

9. Shell Programming and Scripting

Replace several numbers with respective tag and make a single file

Dear All, I have a final output files as 736645|0| 13879|1| 495563|10| 127933|14| 4975|16| 49038|6| 53560|7| 135115|8| 178857|9| Now I want to replace second column with respective tag as per the value (4 Replies)
Discussion started by: jojo123
4 Replies

10. Shell Programming and Scripting

Single to multiple line file

I am working with single line file with 589744523 characters having 542 "^M" (line feed) character. I want to make 542 different lines file from the single line file thr. shell program only (it can be done thr vi command) rd anil sorry for duplicate post previously, actually i don,t know... (6 Replies)
Discussion started by: anil_kut
6 Replies
Login or Register to Ask a Question