title: bash- Remove a string using sed
body: <p>I have want to delete only the string <code>&quot; - [$the_real_ip]&quot;</code> and one space next to that using <code>sed</code> from the following log stream format:</p>
  <blockquote>
  <p><code>log-format-upstream: '$remote_addr - [$proxy_protocol_addr] - [$the_real_ip] - $remote_user [$time_local] &quot;$request&quot; $status $body_bytes_sent &quot;$http_referer&quot; &quot;$http_user_agent&quot;</code></p>
  </blockquote>
  <p>This is what I tried that doesn't work for me:</p>
  <ol>
  <li>input_file has the above content.</li>
  <li>remove the <code>- [$the_real_ip]</code></li>
  <li>Ran below command.</li>
  </ol>
  <p><code>sed 's/- [$the_real_ip]//g'  input_file &gt; output_file</code></p>
  <p>I am able to remove the <code>[$the_real_ip]</code> using the command:</p>
  <p><code>sed 's/\[$the_real_ip]*\]//g' </code> input_file</p>
  <p>I also wanted to a remove the <code>-</code> next to <code>$the_real_ip]</code> and an extra space created after deleting. How can I do that?</p>