title: How to Replace a line in the same file by SED in Unix Shell scripting?
body: <p>In Reference to <a href="https://stackoverflow.com/questions/1543422/how-to-compare-two-files-in-shell-script">this question</a> 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 I am using SED as below. But Sed only replaces that line in a new file. How can I achieve the update in same file without temporary file (Because those are very huge files).</p>
  
  <pre><code>#!/bin/ksh
  while read line
  do
  var=`echo $line|cut -c 3-25`
  while read i
  do
  var1=`echo $i|cut -c 3-25`
  if [ $var == $var1 ];
  then
  sed -i s/$line/$i/ t1
  else
  
  echo "not matched"
  fi
  done &lt; t2
  done &lt; t1
  </code></pre>
  
  <p>Even without <code>-i</code> option also I am not getting the result. Please help me.</p>
  
  <p><strong>Edit</strong>: Or else suggest me any other optimal way of doing without temporary files or with any scripting languages(less preferred).</p>