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
Sed is designed to work in a pipeline - hence the name "Stream EDitor". Instead, you could use an ex script to edit the file in place. Ex is the line-based text editor on which vi was originally based (not as old as ed, the old bear skins and stone knives text editor, but almost). A simple example that you can modify for your purpose might be as follows:
ex t1 << EOF
$lineNum
s/^.*$/$newline/
w
q
EOF
This script first goes to the line indicated by $lineNum, substitutes the whole line beginning (^) to end ($) with the contents of $newline, then writes and quits. These commands are surrounded by "<
EOF
", which constitute the "here" document, essentially setting up the scripted commands as stdin.