faozhi has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
Is there any way I can make this simpler?
I have several files called sample1.fasta to sample7.fasta
This is the command I would like to do in Unix,  grep -e '^>' sample1.fasta | wc -l ; grep -e '^>' sample2.fasta | wc -l ; (all the way till sample 7)
The number of samples is dynamic and changes, maybe something that I can ask for the user for input.
Appreciate any help, I know it sounds a bit newbish but I am trying to link perl scripts together with unix commands.
Cheers!!

Replies are listed 'Best First'.
Re: Make this simpler?
by toolic (Bishop) on May 17, 2011 at 00:07 UTC
      grep -e '^>' sample*.fast|cut -d\: -f1 |uniq -c

      print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
Re: Make this simpler?
by ikegami (Patriarch) on May 16, 2011 at 23:56 UTC
    for f in sample{1..7}.fasta ; do grep '^>' "$f" | wc -l done

      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.

Re: Make this simpler?
by rustic (Monk) on May 17, 2011 at 14:00 UTC
    Here's one more snippet:
    from the command line just run
    perl -ne 'print grep /^>/, $_' sample*