This is a test version of Biostars. For the public version, visit https://www.biostars.org.
If/Else loop for grep count

Im trying to write an if-else loop that does the following

grep -c ^">" <file>

If results of grep are >0, move file to location1 Else move file to location 2

So far i have:

def numfasta = grep -c ^'>' {input} if [[ $numfasta -gt 0 ]] ; then mv {input} {output.denoise} else mv {input} {output.rerep} fi

but this is not working

Thanks

grep if else python snakemake

In the future please highlight code with the format bar.

enter image description here

No problem at all, was just a reminder :-) It simply makes post more structured and this in turn increases your chance of a good answer.

1 answer

 for F in ~/*.txt ~/*.fa ; do (grep '^>' -m1 "${F}" && mv "${F}" "DIR1") || mv "${F}" DIR2  ; done

Log in to answer this question.