Grep : Display's the lines after the results( -A, -B, -C)

 
[prabhucloudxlab@cxln4 ~]$cat>hello.sh

#! bin/bash

echo " enter filename is search text from "
read filename

if [[ -f $filename ]]
then
echo "enter the text1 to search"
read grepvar1

grep -A1 -n $grepvar1 $filename
echo "============================================================="

grep -B1 -n $grepvar1 $filename
echo "============================================================="

grep -C1 -n $grepvar1 $filename
echo "============================================================="
else
echo "$filename does not exist"
fi


: '
grep -A/ grep -B/ grep -C
grep -A command is used to display the line after the result.
grep -B command is used to display the line before the result.
grep -C command is used to display the line after and line before the result.
'



[prabhucloudxlab@cxln4 ~]$ sh hello.sh
 enter filename is search text from
filegrep.txt

enter the text1 to search
windows

2:This is windows
3-This is MAC
--
5:This is windows
6-This is MAC
--
9:This is windows
10-This is MAC
--
12:This is windows
13-This is MAC
--
15:This is windows
16-This is MAC
--
18:This is windows
19-This is MAC
--
21:This is windows
22-This is MAC
--
24:This is windows
25-This is MAC
=============================================================
1-This is linux
2:This is windows
--
4-This is linux
5:This is windows
--
8-This is linux
9:This is windows
--
11-This is linux
12:This is windows
--
14-This is linux
15:This is windows
--
17-This is linux
18:This is windows
--
20-This is linux
21:This is windows
--
23-This is linux
24:This is windows
=============================================================
1-This is linux
2:This is windows
3-This is MAC
4-This is linux
5:This is windows
6-This is MAC
--
8-This is linux
9:This is windows
10-This is MAC
11-This is linux
12:This is windows
13-This is MAC
14-This is linux
15:This is windows
16-This is MAC
17-This is linux
18:This is windows
19-This is MAC
20-This is linux
21:This is windows
22-This is MAC
23-This is linux
24:This is windows
25-This is MAC
=============================================================