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:
parent
fa6af85b8e
commit
18bfd1ac68
2 changed files with 59 additions and 0 deletions
|
@ -605,3 +605,19 @@ fn test_line_bytes() {
|
|||
assert_eq!(at.read("xac"), "cccc\ndd\n");
|
||||
assert_eq!(at.read("xad"), "ee\n");
|
||||
}
|
||||
|
||||
#[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");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue