The awk
only solution (N here equals 30 files):
awk 'BEGIN{ cmd="wc -l <sourcefile.txt"; cmd|getline l; l=int((l+29)/30); close(cmd) }
NR%l==1{trgt=sprintf("prog%d",((++c)))}{print >trgt"/myfile.txt"}' sourcefile.txt
Or let shell run and return the number of lines in sourcefile.txt and pass to awk
as suggested by jthill.
awk 'NR%l==1{trgt=sprintf("prog%d",((++c)))}{print >trgt"/myfile.txt"}'
l=$(( ($(wc -l <sourcefile.txt)+29)/30 )) sourcefile.txt