split -l 100 input.txt batch_ writes hundred-line files. The logic is simple and the boundary conditions are where hand-rolled versions go wrong.
The last batch is smaller
1,050 rows in batches of 100 gives ten full batches and one of fifty. Code that assumes every batch is full will either drop the remainder or pad it with empty entries โ and an empty entry submitted to an API is frequently accepted as a valid empty record.
Exact multiples produce an empty batch
With 1,000 rows and a size of 100, a loop written as while offset <= total produces an eleventh empty batch. while offset < total does not. This is the single most common chunking bug.
Headers belong in every batch
If the source has a header row, each batch needs its own copy, and the header must not be counted toward the batch size. Splitting a CSV by line count without accounting for the header gives every batch after the first no header at all.
Batching is not the same as rate limiting
Splitting into batches says nothing about how fast you send them. An API with a per-request cap usually also has a per-minute one.
Try it: Split List into Batches on SeoWolf's Notepad.