in reply to Make this simpler?

for f in sample{1..7}.fasta ; do grep '^>' "$f" | wc -l done

Replies are listed 'Best First'.
Re^2: Make this simpler?
by marinersk (Priest) on May 17, 2011 at 12:09 UTC

    I'm still a bit of a n00B in the Unix/Linux space, but it seems you are pre-conceiving 1-7, but the OP indicated the number of files was actually variable.

    So I suspect this tweak would do it:

    for f in sample*.fasta ; do grep '^>' "$f" | wc -l done

    But I'm willing to be wrong; I often am.

      Are the file returned in sorted order? If not, you have no way of reconciling the counts with file names. That may or may not be important.

      I gave code that was equivalent to the OP's code, but it may very well be that your code is better.

        D'oh! No, I do not believe they are guaranteed to come back in sorted order, though I believe I have seen implementations that happen to do so.

        I'll just go back to my corner now. :: grin ::