Re: [SLUG] Slicing a file

From: Daniel Jarboe (daniel.jarboe@gmail.com)
Date: Fri May 26 2006 - 07:44:36 EDT


> A (real) example of the above would be (assuming original file contains
> 10000 lines, and needs splits of 2000, 3000, 3000 and 2000):
>
>
> head -n 2000 original > result1
> tail -n 8000 original > temp1
> head -n 3000 temp1 > result2
> tail -n 5000 temp1 > temp2
> head -n 3000 temp2 > result3
> tail -n 2000 temp2 > result4
>
> The above will work, but leaves temp files potentially all over the
> place (temp1 and temp2). If necessary, I can do that. But it would be
> better to create the exact "chunks" from a file without any extra files
> lying around.

If you wanted to avoid files you could do some head/tail pipery, but
sed can accomplish the same thing:

sed '1,2000!d' original > result1
sed '2001,5000!d' original > result2
sed '5001,8000!d' original > result3
sed '8001,10000!d' original > result4

in a nutshell, delete (d) every line that is not (!) in the line range
specified.

The opposite works too... like sed -n '2001,5000p' original ...
disable autoprint (-n), print (p) the line range specified.
~ Daniel
-----------------------------------------------------------------------
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:01 EDT