Hi

I have a folder with 4000 files in it. I would like make a new folder, and copy into it all of the files which contain >50 fasta sequences. How do I do this?

I know that I need to create a simple loop, then  grep '>'  | wc -l and select only those with >50. But I am new to programming and am unsure how to write this properly. 
This is a very interesting question, but you should implement it without a FOR loop, which are a bad thing.

For example you can do it with find:

    mkdir -p smallfiles_folder/
    find .  -type f  -print0 | xargs -0 grep -m 50 -o -H -c '>'  | gawk -F":" '$2 > 2 {print $1} ' | grep -v 'smallfiles_folder' | xargs -i cp {} smallfiles_folder/



Explanation:

    # find all files in current folder. Add -iname "*fasta" to restrict to fasta files only
    find .  -type f  -print0 |     
     
      # count number of fasta headers in file. The -m 50 option is used to stop grepping after 50 matches, saving some calculation time) \
     xargs -0 grep -m 50 -o -H -c '^>'  | 
     
     # Use files to select files with less than 50 matches
     gawk -F":" '$2 < 50 {print $1} ' | 

     # Remove target folder (avoid potential recursive loops)
     grep -v 'smallfiles_folder' | 

     # copy / move files to target folder
     xargs -i cp {} smallfiles_folder/
