Re: counting the number of commas

From: bird (bird_at_village.org)
Date: 04/25/05


Date: Mon, 25 Apr 2005 13:32:51 -0500

Chris F.A. Johnson wrote:
> On Mon, 25 Apr 2005 at 12:47 GMT, bird wrote:
>
>>I have a text file. I need to count the number of commas on each line
>>of the file. Is there any good way to do it?
>
>
> If you need it line by line:
>
> awk '{print gsub(/,/,"")}' FILENAME
>
>
> If you just need the total for the file:
>
> file=$( < FILENAME )
> file=${file//[^,]/}
> echo ${#file}
>
> If the file is really big, awk might be faster:
>
> awk '{total += gsub(/,/,"")} END {print total}' FILENAME
>

Thank you all for your kindly help. These are what I am
looking for. Thank you again.



Relevant Pages