I would like to remove all the newline character that occurs after a partiular string and replace it with a tab space. Say for instance my sample.txt is as follows
The sed version looks like
#!/bin/sed -f
/foo/{
N
s/\n/\t/
}
If this is all you want to do in your sed command, you can simplify the above to a one-liner:
sed -e '/foo/N;y/\n/\t/'
Explanation: N appends a newline and the next line of input; y/\n/\t replaces all newlines with tabs, or s/\n/\t/ replaces the first newline with a tab.
Note that since sed is line-oriented, the newlines in the input are considered line-separators rather than as part of any line (this is in contrast e.g. to Perl).