Q:

How to search for a pattern in a file and store it in a variable using shell script? Please give an example

suppose in a file if I have " Route : 8888" , I want to get the string after the pattern "Route :"
I have used sed command, but it is printing 8888 but I want to store it into a variable and use for further processing 

A:

So store sed's output in a variable:
ROUTE_VALUE=$(sed ... <file.txt)

Where '...' is your sed command.
$ cat rt.sh
ROUTE=`sed -n 's/.*Route = \(.*\),.*/\1/p' data.txt`
echo $ROUTE
$ bash rt.sh
8888
$ source rt.sh
8888

