title: how to cut a string using length in unix shell
body: <h2>Edited</h2>
  
  <p>I have a problem in finding a pattern in a string. Actually i want to compare two files and replace content of file1 to file 2 having the below content</p>
  
  <h3>File1</h3>
  
  <p><code>000123   moorsevi har      NC asee    terel</code><br>
  <code>000125   staevil strd      NC klass   aklsd</code><br>
  <code>000126   carolie asdr      NC skdkld  kaks</code><br>
  <code>000128   histvil df        NC lllas   kasd</code>  </p>
  
  <h3>File2</h3>
  
  <p><code>000123   moorsevile har    NC asee    terel</code><br>
  <code>000125   staevile strd     NC klass   aklsd</code><br>
  <code>000126   caroline asdr     CA skdkld  kaks</code>   </p>
  
  <p>Here i have to match first column and replace the column 2&amp;3 in file2, where length of the line in file2 should not changed.</p>
  
  <p>i have tried with the below code.</p>
  
  <pre><code>#! /bin/ksh
  IFS=$
  ite=0
  while read -r line
  do
      seqno=$(echo $line|cut -c1-9)
      add=$(echo $line |cut -c10-28)
      state=$(echo $line|cut -c29-31)
      echo "seq no:[$seqno] add:[$add] state:[$state]"
      line1=$(grep $seqno file1)
      add1=$(echo $line1|cut -c10-28)
      state1=$(echo $line1|cut -c29-31)
  
      echo "on file 1 address:[$add1]: state:[$state1]"
  
      sed -e "s/$add/$add1/g" -e "s/$state/$state1/g" file2 |tee file2
  
      ite=`expr $ite + 1`
      echo "iteration= $ite"
  done &lt;file2
  IFS="\n"
  echo "IFS:[$IFS]"
  </code></pre>
  
  <h3>Expected Output:</h3>
  
  <h3>File2</h3>
  
  <p><code>000123   moorsevi har      NC asee    terel</code><br>
  <code>000125   staevil strd      NC klass   aklsd</code><br>
  <code>000126   carolie asdr      NC skdkld  kaks</code>   </p>
  
  <p>Shell experts in this forum conveyed that using awk is the right way </p>
  
  <p>show me some light on achieving the solution using awk.</p>