title: How to find and replace the text in shell script
body: <p>I am a new bie to shell scripting, here i am trying to find the text and replace the text using the shell script.</p>
  
  <p>what i am trying to do is, actually i have a text file which has 2 strings separated by ":
  "</p>
  
  <p>Like this</p>
  
  <pre><code>lorem:ipsum
  dola:meru
  etc....
  </code></pre>
  
  <p>my script will take 2 parameters while running.
  now the script should check if first parameter is found or not if not found it should add it to text file.</p>
  
  <p>if the first parameter is found, then it should replace the second parameter.</p>
  
  <p>for example</p>
  
  <p>The text file has data like this</p>
  
  <pre><code>lorem:ipsum
  dola:meru
  caby:cemu
  </code></pre>
  
  <p>i am running my script with 2 parameters like this</p>
  
  <pre><code>./script.sh lorem meru
  </code></pre>
  
  <p>So when i run the script it should check if the first parameter found in the file if found, the script should replace the second string..</p>
  
  <p>i.e
   I ran the script like this </p>
  
  <pre><code>./script.sh lorem meru
  </code></pre>
  
  <p>so in the file</p>
  
  <pre><code>lorem:ipsum
  dola:meru
  caby:cemu
  </code></pre>
  
  <p>after running the script, in the line</p>
  
  <pre><code>lorem:ipsum
  </code></pre>
  
  <p>should get replaced to </p>
  
  <pre><code>lorem:meru
  </code></pre>
  
  <p>here is what i have tried..</p>
  
  <pre><code>#!/bin/sh
  #
  FILE_PATH=/home/script
  FILE_NAME=$FILE_PATH/new.txt
  
  echo $1
  echo $2 
  if []   then     
  else 
  echo $1:$2 &gt;&gt; $FILE_NAME
  fi
  </code></pre>