coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: split: Allow splitting by line count (instead of byte size)


From: Pádraig Brady
Subject: Re: split: Allow splitting by line count (instead of byte size)
Date: Tue, 12 Jan 2021 13:31:46 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Thunderbird/84.0

On 12/01/2021 03:17, William Bader wrote:
I think that split has to be able to read from pipes, so if it reads to the end 
to find the number of lines, it can't back up to do the split.
If you don't care about the order of the lines, you could use "split 
--number=r/2"

Good point RE --number=r/2 being an option.

Reading from pipes is only partly the reason we don't support this 
functionality.
The same arguments can be applied to "bytes" and "lines" as enumerators,
and we support this functionality with bytes.
Though when reading from pipes we error out as appropriate:

  $ split -n2 -
  split: -: cannot determine file size

If we we're to support this, we'd add something like
the following to --number:

  L/N    split into N files with an equal number of lines per file
  L/K/N  output Kth of N to stdout with equal number of lines per file

The disadvantage is that we'd be pulling some wc logic into split,
but it wouldn't be providing any efficiency advantages.
Achieving this in shell is also simple enough and portable

  lines=$(($(wc -l < "file") / 2))
  split -l $lines file

Now L/K/N above would be new functionality provided,
though I'm not sure if it's useful enough to warrant the addition.

I'm 50:50.

cheers,
Pádraig



reply via email to

[Prev in Thread] Current Thread [Next in Thread]