title: Write into a certain line number of a file using a variable
body: <p>In a shell script, I get the certain number of a line in a file and store it in a variable using the code below:</p>
  
  <pre><code>res=$(grep -n '123' somefile.txt | sed 's/^\([0-9]\+\):.*$/\1/')
  </code></pre>
  
  <p>Now I want to write in 3 lines after this line, so I used these codes :</p>
  
  <pre><code>sed -i '$res\anything' somefile.txt
  sed -i '$resianything' somefile.txt
  </code></pre>
  
  <p>but they don't work.  It seems that <code>sed</code> doesn't accept variables.
  How can I solve it? Is there any alternative way?</p>