title: SED command not functioning correctly
body: <p>I have a file test.file which has following lines.</p>
  
  <pre><code>abc01.hostname.com
  xyzabc01.hostname.com
  xyzabc02.hostname.com
  </code></pre>
  
  <p>I have script - for sed which should print output as below</p>
  
  <pre><code>[abc]
  abc01.hostname.com
  [xyzabc]
  xyzabc01.hostname.com
  xyzabc02.hostname.com
  </code></pre>
  
  <p>But I'm getting below output.</p>
  
  <pre><code>[abc]
  abc01.hostname.com
  [abc]
  [xyzabc]
  xyzabc01.hostname.com
  xyzabc02.hostname.com
  </code></pre>
  
  <p>Don't know why [abc] is getting duplicated. Any suggestions?
  below is the script which I am using.</p>
  
  <pre><code>#!/bin/bash
  for i in `test.file | cut -d. -f1 | sed 's/[0-9]//g' | uniq`
  do
      {
          name=$(cat test.file | grep ^$i[0-9] | head -1)
          sed -i "/$name/i \[$i\]" test.file
      }
  done
  </code></pre>