title: grep a character/word from a string and count number of occurrences in Linux
body: <p>I like to a grep a character from a string then count it, I don't see from google search. Please advise. I might miss search for it. </p>
  
  <pre><code>node_count=`echo "test1|test2|test3" | grep "|" |wc -l`|echo $node_count
  </code></pre>
  
  <p>output is always 1 to me.</p>
  
  <pre><code>1
  </code></pre>
  
  <p>Remember that I don't grep from a file but a line of string. Grep from a file is easy.</p>