1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

split: implement round-robin arg to --number

Implement distributing lines of a file in a round-robin manner to a
specified number of chunks. For example,

    $ (seq 1 10 | split -n r/3) && head -v xa[abc]
    ==> xaa <==
    1
    4
    7
    10

    ==> xab <==
    2
    5
    8

    ==> xac <==
    3
    6
    9
This commit is contained in:
Jeffrey Finkelstein 2022-01-02 22:38:27 -05:00
parent bb27734f6a
commit 7dc96697c9
2 changed files with 60 additions and 0 deletions

View file

@ -743,3 +743,19 @@ fn test_hex_suffix() {
assert_eq!(at.read("x0b"), "c");
assert_eq!(at.read("x0c"), "");
}
#[test]
fn test_round_robin() {
let (at, mut ucmd) = at_and_ucmd!();
let file_read = |f| {
let mut s = String::new();
at.open(f).read_to_string(&mut s).unwrap();
s
};
ucmd.args(&["-n", "r/2", "fivelines.txt"]).succeeds();
assert_eq!(file_read("xaa"), "1\n3\n5\n");
assert_eq!(file_read("xab"), "2\n4\n");
}