I am familiar with shell programming in bash, but for some reason egrep -o to print only matching words is not working and displays error as below.
egrep -o
Envi
If you have perl :
perl
echo "I am a boy" | perl -lne '/am/ && print $&' am