faSplit (linux version linked/ macOS available) from Kent Utilities will take care of the fasta file split.
Instead of "sorting" you may want to change the title to "splitting".
For fastq files you could do:
split -l 4 -d -a 500 your_file.fq SEQ. Use a different word instead of
SEQ to use that as file name PREFIX.