cat>filegrep.txt
This is linux
This is windows
This is MAC
This is linux
This is windows
This is MAC
This is linux
This is windows
This is MAC
This is linux
This is windows
This is MAC
This is linux
This is windows
This is MAC
This is linux
This is windows
This is MAC
This is linux
This is windows
This is MAC
This is linux
This is windows
This is MAC
[prabhucloudxlab@cxln4 ~]$ cat>hello.sh
#search for a specific pattern using ‘awk’
#! /bin/bash
echo "enter filename to print from awk"
read fileName
if [[ -f $fileName ]]
then
awk '/linux/ {print}' $fileName
else
echo "$fileName doesn't exist"
fi
[prabhucloudxlab@cxln4 ~]$ sh hello.sh
enter filename to print from awk
filegrep.txt
This is linux
This is linux
This is linux
This is linux
This is linux
This is linux
This is linux
This is linux