I suggest some reading.
here to read about the sed command
here to read about shell scripting
both of those took me two min to find on google. Do some research before you start asking questions. everything you have asked can be found in numerous sources and with a little effort you would have found them yourself.