fork(1) download
  1. #!/bin/bash
  2. cd $(mktemp -d)
  3.  
  4. IFS='' read -r header
  5. for ((curr_file_max_rows=1; 1 ; curr_file_max_rows*=2)) {
  6. curr_file_name="file_with_${curr_file_max_rows}_rows"
  7. echo "$header" > "$curr_file_name"
  8. for ((curr_file_row_count=0; curr_file_row_count < curr_file_max_rows; curr_file_row_count++)) {
  9. IFS='' read -r row || break 2
  10. echo "$row" >> "$curr_file_name"
  11. }
  12. }
  13.  
  14. echo "files generated :"
  15. ls
  16. echo
  17.  
  18. echo "content of file_with_1_rows :"
  19. cat file_with_1_rows
  20. echo
  21.  
  22. echo "content of file_with_2_rows :"
  23. cat file_with_2_rows
  24. echo
  25.  
  26. echo "content of file_with_16_rows (with less than 16 rows because we reached the end of the input) :"
  27. cat file_with_16_rows
  28. echo
Success #stdin #stdout 0s 4340KB
stdin
header
row1
row2
row3
row4
row5
row6
row7
row8
row9
row10
row11
row12
row13
row14
row15
row16
row17
row18
row19
row20
row21
row22
row23
row24
row25
row26
row27
stdout
files generated :
file_with_16_rows
file_with_1_rows
file_with_2_rows
file_with_4_rows
file_with_8_rows

content of file_with_1_rows :
header
row1

content of file_with_2_rows :
header
row2
row3

content of file_with_16_rows (with less than 16 rows because we reached the end of the input) :
header
row16
row17
row18
row19
row20
row21
row22
row23
row24
row25
row26