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




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 01-04-2009
jaduks's Avatar
jaduks jaduks is offline
Registered User
  
 

Join Date: Aug 2007
Location: Assam,India
Posts: 166
RahulJoshi,

Not sure if this is the requirement you are asking.

Code:
$ split -d -l 6 bigfile subfile

will create subfile00 subfile01 .... with each file of 6 lines

As you want 3 files in output, the l value has to be caluculated like this:

$ awk 'END {printf("%d\n",NR/3+.5)}' bigfile

------------
** The above way of rounding may go wrong in some cases, e.g. suppose the file is having 17 lines, 

$ awk 'END {printf("%d\n",NR/5+.5)}' bigfile
3

then,

$ split -d -l 3 bigfile subfile

will create 4 subfiles, which is wrong. 
------------

I am sure there can be better solutions to this. Group please.

Last edited by jaduks; 01-04-2009 at 10:26 PM.. Reason: typo