Re: [SLUG] Slicing a file

From: Dylan William Hardison (dylan@hardison.net)
Date: Fri May 26 2006 - 10:44:30 EDT


Spake Paul M Foster on Friday, May 26, 2006 at 02:17AM -0400:
> Eben King wrote:
> >On Fri, 26 May 2006, Paul M Foster wrote:
> >
> >>Here's what I need to do (sometimes): Take a text file and split it
> >>into pieces. The split command won't work for this, because the pieces
> >>may not be equal. For example, I may want to split an 8000 line file
> >>into pieces 2000, 3000 and 3000 lines each. I'm willing to run the
> >>same command multiple times with different parameters, but whatever I
> >>use needs to be some common command expected to be there on any
> >>system. I've looked at split, head and tail. I suspect I can do this
> >>with sed or awk, but I'm not very familiar with those two, beyond
> >>rudimentary use. Can anyone suggest a solution?
> >
> >Find out what line is the first that should be in the second file (call
> >it L).
> >
> >head -n L-1 filename > file1
> >tail +L filename > file2andLater
> >
>
> (Note: I'm not using a second file to tell me where the splits should be.)
>
> A (real) example of the above would be (assuming original file contains
> 10000 lines, and needs splits of 2000, 3000, 3000 and 2000):

with the ginsu.pl in another reply of mine, you'd:

perl ginsu.pl bigfile 2000 3000 3000 2000

-- 
...the number of UNIX installations has grown to 10, with more expected...
              -- Dennis Ritchie and Ken Thompson, June 1972
-
GPG Fingerprint: E3CD FDAB 82C4 14FD 7B57  430B 770E 0EAF FB53 12C2
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 19:23:51 EDT