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 21:25:58 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Thunderbird/84.0

On 12/01/2021 18:55, William Bader wrote:
lines=$(($(wc -l < "file") / 2))
split -l $lines file

Doesn't this need to round up to avoid leaving a third file with one line if 
the original file has an odd number of lines?

split -l $((($(wc -l < file) + 1) / 2)) file

Well dealing with remainders would be an argument for implementing
--number=L/N as it could distribute lines more evenly.

I.e. --number=L/N would be like l/N, but it would
try harder to evenly distribute lines,
by identifying the number of lines up front,
and determining which chunks would get an extra line
to cater for the remainders.

cheers,
Pádraig



reply via email to

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