Write a shell script that searches for a particular pattern in files and displays the name of such files
Write a shell script that searches for a particular pattern in files and displays the name of such files
Code:
clear
echo ------------------------------------------------------------
echo '\tsearches for a particular pattern in files'
echo ------------------------------------------------------------
echo Enter the word to searches for a particular pattern in files
read wname
echo Result a particular pattern:
for File in *
do
if [ -r $File ]
then
if [ $(grep $wname $File | wc -w) -gt 0 ]
then
echo $File.
fi
fi
done
Output:
------------------------------------------------------------
searches for a particular pattern in files
------------------------------------------------------------
Enter the word to searches for a particular pattern in files
satheesh
Result a particular pattern:
name_a.
name_asce.
name_desc.
satheesh.
vino.
Leave a Comment