Matthew Gregan wrote:
At 2004-11-07T21:23:55+1300, Chris Downie wrote:
I have a text file that I need to count exactly how many times a
particular character appears.
Here's something that isn't particularly efficient, but it's very simple:
$ sed -e 's/[^A]//g' | wc -c
Subsitute 'A' with the character you need to count.
Can someone offer me the correct grep syntax to achieve this?
grep(1) is line-oriented, so it's rather difficult to achieve what you want with grep.
Cheers,
-mjg
I was trying to do the same with tr but failed, and came up with...
#!/bin/bash
Count=`cat $1 | wc -c | awk '{print $1}'`
Count2=`cat $1 | tr -d $2 | wc -c | awk '{print $1}'`
echo `expr $Count - $Count2`Where args are filename and character. Far less elegant (:
And slower, of course.
Steve
