[ale] Bash script question
Geoffrey
esoteric at 3times25.net
Wed May 14 21:21:34 EDT 2003
Just threw this together, tested it for a few seconds, seems to work:
awk -F',' 'BEGIN {count=0;}
{if (NF == 0) {next;}; count= count + NF - 1}
END {print count}'
Test a bit before you take my word. Pass the character you want to
count as the field delimiter (-F','). Then, any line that contains one
or more of the character will have one field more then the number of
that character. This will work even if the character is the only
character on the line. If the number of fields is 0, don't adjust the
count.
Bob Kruger wrote:
> Is there a utility that I can run from bash that I can use to determine
> the number of times a certain character appears in a line?
>
> Example - I want to determine the number of times a comma (,) appears in
> the line:
>
> Field1,Field2,Field3,
>
> Yes, it can be done from Perl, but I would like to do this from bash.
>
> Thanks in advance for any assistance.
>
> Bob
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
>
>
--
Until later: Geoffrey esoteric at 3times25.net
The latest, most widespread virus? Microsoft end user agreement.
Think about it...
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale
More information about the Ale
mailing list