![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Splitting a file based on the records in another file | er_ashu | Shell Programming and Scripting | 2 | 05-12-2008 01:34 PM |
| Number Grouped Rows in File | RacerX | UNIX for Dummies Questions & Answers | 2 | 03-03-2008 12:36 PM |
| Splitting av file in 2 at specific place based on textpattern | borgeh | Shell Programming and Scripting | 0 | 09-24-2007 04:02 PM |
| splitting files based on text in the file | matrix1067 | Shell Programming and Scripting | 1 | 01-30-2006 05:45 PM |
| Splitting a file based on some condition and naming them | srivsn | Shell Programming and Scripting | 1 | 12-07-2005 08:27 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Splitting file based on number of rows
Hi,
I'm, new to shell scripting, I have a requirement where I have to split an incoming file into separate files each containing a maximum of 3 million rows. For e.g: if my incoming file say In.txt has 8 mn rows then I need to create 3 files, in which two will 3 mn rows and one will contain 2 mn rows. The number of rows in In.txt will vary. My Algorithm is as follows: I would first do a wc -l on In.txt to get no: of rows Divide the count/3mn to get no: of files to be created (8/3=2.66 ~3) Then in a loop use head and tail commands to transfer rows into files into new file The above algorithm will work, but I think using awk there may be something easier. Please let me know if there is a faster and easier way of doing this Regards Wahi |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
I used the split command which reduced the code to one line
|
|
#3
|
|||
|
|||
|
After getting number of rows in one file, you can use sed to split it
Code:
sed '$begin_from,$last_to w new_file1' original_file |
|||
| Google The UNIX and Linux Forums |