Sunday, April 17, 2005

Find number of occurrences of a word

To get the number of occurrences of a word (e.g. ServerName) in a file (e.g. httpd.conf), do a:

grep -c ServerName httpd.conf

For a line occurrence frequency count report:

sort httpd.conf | uniq -c | sort -nr

For a word occurrence frequency count report:

sed -e 's/\.//g' -e 's/ //g' "httpd.conf" | tr 'A-Z' 'a-z' | sort | uniq -c | sort -nr

No comments: