title: insert a file after a specific line
body: <p>I want to insert some text at some particular position in a file using shell script say for example at line 3 in a file.</p>
  
  <p>I have an input file:</p>
  
  <pre><code>input.txt
  ---------
  Apple
  Orange
  Cat
  Dog
  </code></pre>
  
  <p>and another sample file:</p>
  
  <pre><code>sample.txt
  -----------
  Sample data1
  Sample data2
  </code></pre>
  
  <p>Now my output file should be like:</p>
  
  <pre><code>output.txt
  ----------
  Apple
  Orange
  Sample data1
  Sample data2
  Cat
  Dog
  </code></pre>
  
  <p>I have written a script but it can place only on beginning of the file:</p>
  
  <pre><code>#!/bin/bash
  if grep  "Text exists..." "./input.txt"; then
  echo exist
  else
     echo doesNOTexist
     cat sample.txt &gt;&gt; output.txt
     cat input.txt &gt;&gt; output.txt
  fi
  </code></pre>
  
  <p>Please help me how to insert lines at some specific position instead of beginning or end of the file.</p>
  
  <p>I am using UNIX with bash shell.</p>