Search and Count A Single Word Pattern Recursively In A UNIX File
From X86wiki
#!/bin/bash # Search UNIX file / Linux file for a pattern recursively # ------------------------------------------------------------------------- # Copyright (c) 2007 nixCraft project <http://cyberciti.biz/fb/> # This script is licensed under GNU GPL version 2.0 or above # ------------------------------------------------------------------------- # This script is part of nixCraft shell script collection (NSSC) # Visit http://bash.cyberciti.biz/ for more information. # ------------------------------------------------------------------------- echo -n "Enter a one word pattern : " read pattern # word / name search using grep and count COUNT=$(grep -wr "${pattern}" . 2> /dev/null | wc -l) echo "${pattern} occured ${COUNT} times."