In Reference to this question After getting the line identifier matching in first and second file I need to replace the line in first file with the line of second file.For that
Have a look at sponge which is part of moreutils.
e.g.
% sed "s/root/toor/" /etc/passwd | grep -v joey | sponge /etc/passwd