Bash regexp: How to replace all non-whitespace characters with a letter?
<p>I have a text file that contains a lot of whitespace and some other ASCII characters. I would like to use Bash (preferably via <code>sed</code>) to replace any non-whitespace characters in the file with the letter <code>M</code>. How would I go about doing this?</p>

<p>Thanks for helping.</p>

<p><strong>edit:</strong> For the downvoters, I tried running this:</p>

<pre><code>sed -i 's/[^\s]/M/g' file
</code></pre>

<p>and this:</p>

<pre><code>sed -i 's/[^\s]/M/' file
</code></pre>

<p>but neither of them worked out too well. I'm a little unfamiliar with regex, so apologies if I'm doing something obviously wrong.</p>