Daniel Jarboe wrote:
>> 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.
I like your sed solution.
The head tail pipery is just as fun, and no temporary files.
head -2000 origional > result1
head -5000 origional | tail +2000 > result2
head -8000 origional | tail +5000 > result3
head -10000 origional | tail +8000 > result4
Using tail with a plus ("+") count is quite useful for this.
This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 19:23:26 EDT