How to count the number of bold words and italic words in a markdown syntax file
<p>I've read that bold and italic words can be represented in markdown language by ** <strong>bold_text</strong> ** and * italic_text *, respectively. To have a both bold and italic text at once, you can wrap the text with 4 asterisks for bold and 2 underscores for italic (or vice versa).</p>

<p>I would like to write a bash script which determines the number of bold words and italic words. I guess that this comes down to counting the number of double asterisks , single asterisks, double underscores and single underscores. My question is how to count the number of specific strings like "**" or "__" from a file, so I can know how many bold and italic words there are.</p>

<pre><code>#!/bin/bash

if [ -z "$1" ]; then
    echo "No input file specified."
else 
    ls $1 &gt; /dev/null 2&gt; /dev/null &amp;&amp; 
    echo $(cat $1 | grep -o '\&lt;**&gt;\' | wc -c) || echo "File $1 does not exist."
fi
</code></pre>

<p>Example input file:</p>

<pre><code>**This is bold and _italic_** text.
</code></pre>

<p>Expected output:</p>

<pre>
Bold words: 5
Italic words: 1
Bold and italic words: 1
</pre>