title: Add text to specific line linux script
body: <p>I need to create a script that will add text after a specific line in a file (XML). Here is what I have so far:</p>
  
  <pre><code>echo
  echo "This script will blah blah blah"
  echo
  read -p "Press Enter to continue..."
  clear
  
  var1=`grep -n "&lt;string&gt;" &lt;file&gt; | awk -F ":" '{print $1}'` //var1 = line number
  
  function EnterID()
  {
  echo -n "Enter ID: "
  read ID
  var2="text to be added"
  sed "$((var1+1))i$var2" &lt;file&gt; &gt; &lt;file&gt; //add text to file, overwrite file
  #var1="$((var1+1))" //increment line number???
  echo
  echo "ID successfully added to file"
  echo
  EnterNewID
  }
  
  EnterNewID()
  {
  read -p "Press Enter to continue..."
  clear
  echo -n "Would you like to add another ID? (y)es or (n)o: "
  read answer
  clear
  
  if [ $answer = "y" ]; then
      EnterID
  else
      exit
  fi
  }
  
  EnterID
  </code></pre>
  
  <p>The script works the first time around. However, if the users attempts to add an additional ID the first ID is overwritten. I should also state I am not a programmer (more of a network guy). I have a little experience scripting but that's all.</p>
  
  <p>Additional Information:</p>
  
  <p>Original:</p>
  
  <pre><code>&lt;SubscriberXML&gt;
    &lt;Subscribers&gt; 
      &lt;Subscriber address="0.0.0.0" id="1" /&gt;
      &lt;Subscriber address="0.0.0.0" id="2" /&gt;
      &lt;Subscriber address="0.0.0.0" id="3" /&gt;
      &lt;Subscriber address="0.0.0.0" id="4" /&gt;
      &lt;Subscriber address="0.0.0.0" id="5" /&gt;
    &lt;/Subscribers&gt;
  &lt;/SubscriberXML&gt;
  </code></pre>
  
  <p>After initial use:</p>
  
  <pre><code>&lt;SubscriberXML&gt;
    &lt;Subscribers&gt; 
      &lt;Subscriber address="0.0.0.0" id="X" /&gt; // newly added ID
      &lt;Subscriber address="0.0.0.0" id="1" /&gt;
      &lt;Subscriber address="0.0.0.0" id="2" /&gt;
      &lt;Subscriber address="0.0.0.0" id="3" /&gt;
      &lt;Subscriber address="0.0.0.0" id="4" /&gt;
      &lt;Subscriber address="0.0.0.0" id="5" /&gt;
    &lt;/Subscribers&gt;
  &lt;/SubscriberXML&gt;
  </code></pre>
  
  <p>After second use:</p>
  
  <pre><code>&lt;SubscriberXML&gt;
    &lt;Subscribers&gt; 
      &lt;Subscriber address="0.0.0.0" id="Y" /&gt; // newly added ID
      &lt;Subscriber address="0.0.0.0" id="1" /&gt;
      &lt;Subscriber address="0.0.0.0" id="2" /&gt;
      &lt;Subscriber address="0.0.0.0" id="3" /&gt;
      &lt;Subscriber address="0.0.0.0" id="4" /&gt;
      &lt;Subscriber address="0.0.0.0" id="5" /&gt;
    &lt;/Subscribers&gt;
  &lt;/SubscriberXML&gt;
  </code></pre>
  
  <p>Want:</p>
  
  <pre><code>&lt;SubscriberXML&gt;
    &lt;Subscribers&gt; 
      &lt;Subscriber address="0.0.0.0" id="Y" /&gt;
      &lt;Subscriber address="0.0.0.0" id="X" /&gt;
      &lt;Subscriber address="0.0.0.0" id="1" /&gt;
      &lt;Subscriber address="0.0.0.0" id="2" /&gt;
      &lt;Subscriber address="0.0.0.0" id="3" /&gt;
      &lt;Subscriber address="0.0.0.0" id="4" /&gt;
      &lt;Subscriber address="0.0.0.0" id="5" /&gt;
    &lt;/Subscribers&gt;
  &lt;/SubscriberXML&gt;
  </code></pre>