title: Replacing pattern using UNIX commands
body: <p>I have some strings like:</p>
  
  <p>Sample Input:</p>
  
  <pre><code>Also known as temple of the city,
  xxx as Pune Banglore as kolkata Delhi India,
  as Mumbai India or as Bombay India,
  Calcutta,India is now know as Kolkata,India,
  </code></pre>
  
  <p>From the above I want to convert <strong>as xxx xxxx xx,</strong> to <strong>as xxx_xxxx_xx,</strong> and it should be effective after the last <strong>as</strong>.</p>
  
  <p>Sample output for above:</p>
  
  <pre><code>Also known as temple_of_the_city,
  xxx as Pune Banglore as kolkata_Delhi_India,
  as Mumbai India or as Bombay_India,
  Calcutta,India is now know as Kolkata,India,
  </code></pre>
  
  <p>There should be no space separated string after the last <strong>as</strong> in a line.</p>
  
  <p>Please let me know if it is not clear.
  Thanks</p>