$ wc -l test.txt 24 test.txt $ head -3 test.txt 0 1 1 1 1 1 0 1 1 $ awk -f make_common_period_vec_file.awk N=20 per_max=8000 per_min=125 test.txt > new_test.txt $ wc -l new_test.txt 1284 new_test.txt $ expr 20*8000/125+4 | bc 1284 $ cat make_common_period_vec_file.awk BEGIN {FS = "\t"; OFS = "\t";} { if (NR < (N + 1)) { for (i = 0;i<(per_max/per_min);i++) { printf("%s\n",$0); } } else printf("%s\n",$0); } $