Shell Script Searches For A Single Word Pattern Recursively
Posted in Academic
#!/bin/bash # Write a shell script that searches for a single word pattern recursively # in the current working directory and display the numbers of times it occurred. # ------------------------------------------------------------------------- # Copyright (c) 2005 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 one word pattern : " read pattern # wc - word count COUNT=$(grep -wr "${pattern}" . 2> /dev/null | wc -l) echo "${pattern} occurred ${COUNT} times."
Download - Email this to a friend - Printable version
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: echo command, grep command, read command, recursively, script searches, shell script, single word, wc command, word count, word pattern ~ Last updated on: May 5, 2008

