GNU bug report logs -
#9455
RFE: split --balanced
Previous Next
Reported by: Dave Yost <Dave <at> Yost.com>
Date: Wed, 7 Sep 2011 01:02:01 UTC
Severity: wishlist
Fixed in version 8.8
Done: Pádraig Brady <P <at> draigBrady.com>
Bug is archived. No further changes may be made.
Full log
Message #10 received at control <at> debbugs.gnu.org (full text, mbox):
severity 9455 wishlist
thanks
Hi Dave!
Dave Yost wrote:
> Z% for x in 1 2 3 4 5 6 7
> for> do echo $x ; done | split --lines=3 \
> pipe> && for x in x?? ; do echo "=== $x" ; cat $x ; done
Sure. Just fyi but GNU seq can produce sequences of numbers very
easily. I think this is a little more concise example.
seq 1 7 | split --lines=3
head *
But do you always mean stdin? Or mostly is this a file? Because...
> In some applications, you would like split to more evenly apportion
> the output to the files, like this:
>
> Z% for x in 1 2 3 4 5 6 7
> for> do echo $x ; done | split --balanced --lines=3 \
> pipe> && for x in x?? ; do echo "=== $x" ; cat $x ; done
> === xaa
> 1
> 2
> 3
> === xab
> 4
> 5
> === xac
> 6
> 7
I think it would be really hard to know if the user wanted the extra
lines in the first file. It would be easier to gather that last widow
line up into the next to last file. Or easier to leave it alone in
its own file.
seq 1 7 > input.txt
numsplits=3
num=$(wc -l < input.txt)
perfile=$(($num / $numsplits))
split --lines=$perfile < input.txt
head x*
seq 1 17 > input.txt
numsplits=3
num=$(wc -l < input.txt)
perfile=$(($num / $numsplits))
split --lines=$perfile < input.txt
head x*
And from there you could get creative and make a decision based upon
the number of lines in that last file.
if [ $(($num % $numsplits)) -lt $(($num / 2)) ]; then ...
If the widow lines are less than half the number of total lines in the
files then that last file could be concatenated into the next to last
file, the implementation of which I will leave as an exercise. Just
as an example. Or they could be put in the first file. But I think
what the user would want in something like this is so varied that
there isn't any one natural result. So I think this is better left to
the caller to decide.
Bob
This bug report was last modified 13 years and 339 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.