title: How to add a # before any line containing a matching pattern in BASH?
body: <p>I need to add a <code>#</code> before any line containing the pattern "000", e.g., consider this sample file:</p>
  
  <pre><code>This is a 000 line.
  This is 000 yet ano000ther line.
  This is still yet another line.
  </code></pre>
  
  <p>If I run the command, it should add <code>#</code> to the front of any files where "000" was found. The result would be this:</p>
  
  <pre><code>#This is a 000 line.
  #This is 000 yet ano000ther line.
  This is still yet another line.
  </code></pre>
  
  <p>The best I can do is a while loop, like this, which seems too complicated:</p>
  
  <pre><code>while read -r line
  do
      if [[ $line == *000* ]]
      then
            echo "#"$line &gt;&gt; output.txt
      else
            echo $line &gt;&gt; output.txt
      fi
  done &lt; file.txt
  </code></pre>
  
  <p>How can I add a <code>#</code> to the front of any line where a pattern is found? </p>