bash programming question

Michael Jeffrey Tucker yellowdog-general@lists.terrasoftsolutions.com
Mon Jan 26 07:26:01 2004


Just out of curiosity? Why are you interested in creating output like
that? Is this for some reporting software or is this an assignment that
you were given for some other purpose?

Mike

On Sun, 25 Jan 2004, John M Phillips wrote:

> While shell scripts are quit powerful, for myself your application crosses
> the line to where I would use perl.  Pattern searches for "^#" are quite
> easy in perl.
>
> The example below gets the line counts for a single file.  If you create
> this as an executable /usr/local/bin/cmmtCount, then the contents of /etc
> can be listed using
>
>  find /etc -type f -exec cmmtCount {} \;
>
> John Phillips
>
> -----------------------------------------------------
> #!/usr/bin/perl -w
>
>     my $lineTotal = 0;          # count of total lines
>     my $lineCmmt  = 0;          # count of lines with leading #
>     my $file      = $ARGV[0];   # file name
>
>     if (open(FILE,$file)) {
>       while ($line=<FILE>) {
>         $lineTotal += 1;
>         if ($line =~ m/^#/) {
>           $lineCmmt += 1;
>         }
>       }
>       print "$file $lineTotal / $lineCmmt\n";
>       close(FILE);
>     }
>     else {
>       print "$file not openned\n";
>     }
>
>
> On 23 Jan 2004, green8 wrote:
>
> > i want to display all the files in folder /etc that i can read, i mean i
> > want to display their names and two numbers next to each of them: their
> > number of lines, and number of lines that NOT start with "#". PLEASE
> > tell  me how to do it just this one time, i won't manage it by myself,
> > thanks, Barti, Poland
> > _______________________________________________
> > yellowdog-general mailing list
> > yellowdog-general@lists.terrasoftsolutions.com
> > http://lists.terrasoftsolutions.com/mailman/listinfo/yellowdog-general
> >
>
> _______________________________________________
> yellowdog-general mailing list
> yellowdog-general@lists.terrasoftsolutions.com
> http://lists.terrasoftsolutions.com/mailman/listinfo/yellowdog-general
>