title: How to search and replace a value in a particular column in unix
body: <p>I am working on a shell script in AIX which has some code to update certain values in a text file. 
  The file is the format as shown below:</p>
  
  <pre><code># cat $FILE
  instance1   13  16
  instance2   14  12
  instance4   58  76
  instance15  44  91
  instance102 31  10
  instance112 12  38
  </code></pre>
  
  <p>I am trying to search by instance name and replace the values in column 2 and column 3 with new values
  I was able to do it using perl as follows:</p>
  
  <pre><code># for i in `cat $FILE|awk '{print $1}'`;do 
  # perl -pi -e "s/`grep -i $i $FILE|awk '{print $2}'`/$NEW_VAL_2/ if /$i/" $FILE
  
  # perl -pi -e "s/`grep -i $i $FILE|awk '{print $3}'`/$NEW_VAL_3/ if /$i/" $FILE
  # done
  </code></pre>
  
  <p>This worked but then I realized that it is replacing every occurrence of the value. For example, in the last row it is replacing the value in column 2 but also the last two characters of the instance name.</p>
  
  <pre><code>Example:
  
      # i = instance112
      # NEW_VAL_2 = 99
      # perl -pi -e "s/`grep -i $i $FILE|awk '{print $2}'`/$NEW_VAL_2/ if /$i/" $FILE
  
      Output:
  
          instance199 99  38
  </code></pre>
  
  <p>How can I search for the row by instance name and replace only the values in a particular column?</p>