#!/bin/bash
cd $(mktemp -d)

IFS='' read -r header
for ((curr_file_max_rows=1; 1 ; curr_file_max_rows*=2)) {
    curr_file_name="file_with_${curr_file_max_rows}_rows"
    echo "$header" > "$curr_file_name"
    for ((curr_file_row_count=0; curr_file_row_count < curr_file_max_rows; curr_file_row_count++)) {
		IFS='' read -r row || break 2
		echo "$row" >> "$curr_file_name"
	}
}

echo "files generated :"
ls
echo

echo "content of file_with_1_rows :"
cat file_with_1_rows
echo

echo "content of file_with_2_rows :"
cat file_with_2_rows
echo

echo "content of file_with_16_rows (with less than 16 rows because we reached the end of the input) :"
cat file_with_16_rows
echo