extract a sub string from a main string

i need a shell program to extract a substring from a main string..
for eg:- main string is madhu..
sub string is mad
o/p:- be mad.
try to solve this one

bijayant@bijayant ~ $ cat test
main string is madhu

bijayant@bijayant ~ $ grep -o mad test2 | echo "be mad"
be mad

i didn't get you :confused::eek:

Oopss...sorry,sorry such a silly typo

It will be
bijayant@bijayant ~ $ grep -o mad test | echo "be mad"
be mad

just echo "be mad" will display be mad..
grep -o is used to show part of matched line.. right??

i need a shell program to extract a substring from a main string..
for eg:- main string is madhu..
sub string is mad
o/p:- mad.
try to solve this one