title: How to incorporate 1 or more spaces in the sed command
body: <p>I have a <code>sed</code> command which comments out <code>cd /path/to/file</code> if not already commented and looks for substring <code>--port 1234</code> and comments out the whole line if not already commented.</p>
  <p>Example input:</p>
  <pre><code>cd /path/to/file
  somecode somecode --port 1234 somecode somecode somecode
  somecode somecode
  cd /path/to/file
  somecode somecode --port 1234 somecode somecode --shutdown
  </code></pre>
  <p>Output:</p>
  <pre><code>#cd /path/to/file
  #somecode somecode --port 1234 somecode somecode somecode
  /new/path/to/file
  somecode somecode
  #cd /path/to/file
  #somecode somecode --port 1234 somecode somecode --shutdown
  /new/path/to/file --shutdown
  </code></pre>
  <p><strong>Here's the solution which works very well:</strong></p>
  <pre><code>sed -E '\@^cd /path/to/file/@s/^/#/;/--port 1234/!b;/^[^#]/!b;s//#&amp;/;p;s#.*(--shutdown).*|.*#/new/path/to/file \1#' file
  </code></pre>
  <p><strong>Problem</strong>:
  However in a case where <code>   cd /path/to/file</code> would be indented by 4 spaces in first occurence and 7 spaces in another occurence: <code>       cd /path/to/file</code>, how would I edit my solution to account for 1 or more spaces? I've been looking all over and I know theres many ways to do it but I can't figure out where to enter that <code>1 or more</code> syntax without breaking the entire solution</p>