title: Remove a particular pattern from string in shell
body: <p>The original string is (according to my format) </p>
  
  <blockquote>
    <p>"cf foo -J 12345 -z -macro TEST_IFDEFINE -macro
    THIS -macro THIS1 -macro THIS2"</p>
  </blockquote>
  
  <p>In order to pass it to another script, I am trying to modify it into   </p>
  
  <blockquote>
    <p>"cf foo -J 12345 -z"</p>
  </blockquote>
  
  <p>To achieve this I have written shell script as follows: </p>
  
  <pre><code>string="cf foo -J 12345 -z -macro TEST_IFDEFINE -macro THIS -macro THIS1 -macro THIS2"
  done=0
  config="-cf"
  name=""
  for name in $string
  do
    if [ $done -eq 1 ];then
      string=`echo $string | sed s/"-macro"//g`
      string=`echo $string | sed s/"$name"//g`
      echo "-----&gt;name: $name"
      macro_name="$macro_name -d $name"
      done=0
      echo "-----&gt;string: $string"
    fi
    if [ "$name" = "-macro" ];then
      done=1
      macro_def=1
    fi
  done 
  </code></pre>
  
  <p>From this code I am getting output is :  </p>
  
  <blockquote>
    <p>cf foo -J 12345 -z 1 2</p>
  </blockquote>
  
  <p>Here, <strong>$name</strong> contains <strong>THIS1</strong> and <strong>THIS2</strong>. But in script when I do </p>
  
  <blockquote>
    <p>| sed s/"$name"//g`</p>
  </blockquote>
  
  <p>it removes only </p>
  
  <blockquote>
    <p>'THIS'</p>
  </blockquote>
  
  <p>But keeping</p>
  
  <blockquote>
    <p>1  2</p>
  </blockquote>
  
  <p>along with original string.
  This means script is discarding only alphabets not numeric values in $name.
  Suggest me something to achieve this.</p>