I have gone through other question which are similar to mine. Following command works, but it doesn't work if I'm trying to remove all the lines except the lines which has string ".c" or ".h".
sed -r -n -e '/.java|.c/p' test.txt
/home/jenkins/workspace/Test/base/src/packages/.c
/home/jenkins/workspace/Test/base/src/packages/.txt
/home/jenkins/workspace/Test/base/packages/Manager.java