To find a given pattern in a list of files of current directory using grep and fgrep commands.

clear
echo "Enter the Name of the file"
read f f1
echo "Searching using Grep"
opt1=y
while [ $opt1 = y ]
do
echo "Enter the pattern you want to search"
read pat
echo "Output of Grep Search"
grep "$pat" $f $f1
echo "Do you want to enter one more pattern for grep"
read opt1
done
opt2=y
echo "Searching using fgrep"
while [ $opt2 = y ]
do
echo "Enter the pattern you want to search"
read p
fgrep "$p" $f $f1
echo "Do you want to enter one more pattern for fgrep"
read opt2
done


OutPut

shaan51@ubuntu:~$ cat>st6
Unix
Windows
ubuntu
shaan51@ubuntu:~$ cat>st7
Unix
keyboard
mouse
shaan51@ubuntu:~$ sh 12
Enter the Name of the file
st6 st7
Searching using Grep
Enter the pattern you want to search
^U
Output of Grep Search
st6:Unix
st7:Unix
Do you want to enter one more pattern for grep
y
Enter the pattern you want to search
U
Output of Grep Search
st6:Unix
st7:Unix
Do you want to enter one more pattern for grep
n
Searching using fgrep
Enter the pattern you want to search
un
st6:ubuntu
Do you want to enter one more pattern for fgrep
y
Enter the pattern you want to search
u
st6:ubuntu
st7:mouse
Do you want to enter one more pattern for fgrep
y
Enter the pattern you want to search
U
st6:Unix
st7:Unix
Do you want to enter one more pattern for fgrep
n

1 comment:

  1. We are urgently in need of KlDNEY donors for the sum of $500,000.00 USD, Email for more details:
    hospitalcarecenter@gmail.com
    WhatsApp +91 779-583-3215

    ReplyDelete