title: Counting number of lines which contain a pattern
body: <p>I have data in the following form:</p>
  
  <pre><code>&lt;id_mytextadded1829&gt;
  &lt;text1&gt;    &lt;text2&gt;    &lt;text3&gt;.
  &lt;id_m_abcdef829&gt;
  &lt;text4&gt;    &lt;text5&gt;    &lt;text6&gt;.
  &lt;id_mytextadded1829&gt;
  &lt;text7&gt;    &lt;text2&gt;    &lt;text8&gt;.
  &lt;id_mytextadded1829&gt;
  &lt;text2&gt;    &lt;text1&gt;    &lt;text9&gt;.
  &lt;id_m_abcdef829&gt;
  &lt;text11&gt;    &lt;text12&gt;    &lt;text2&gt;.
  </code></pre>
  
  <p>Now I want to the number of lines in which <code>&lt;text2&gt;</code> is present. I know I can do the same using python's regex. But regex would tell me whether a pattern is present in a line or not? On the other hand my requirement is to find a string which is present exactly in the middle of a line. I know sed is good for replacing contents present in a line. But instead of replacing if I only want the number of lines..is it possible to do so using sed.</p>
  
  <p>EDIT:
  Sorry I forgot to mention. I want lines where <code>&lt;text2&gt;</code> occurs in the middle of the line. I dont want lines where <code>&lt;text2&gt;</code> occurs in the beginning or at the end of the line.
  E.g. in the data shown above the number of lines which have <code>&lt;text2&gt;</code> in the middle are 2 (rather than 4).</p>
  
  <p>Is there some way by which I may achieve the desired count of the number of lines by which I may find out the number of lines which have <code>&lt;text2&gt;</code> in middle using linux or python</p>