title: Extract text between two XML tags using sed
body: <p>I have XML file similar to the following: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;OnlineCommentary&gt;
      &lt;doc docid="cnn_210085_comment002" articleURL="http://www.cnn.com/News.asp?NewsID=210085" date="10/07/2010" time="00:21" subtitle="Is Justin Bieber getting special treatment?" author="Zorro75"&gt;
          &lt;seg id="1"&gt; They are the same thing. Let's shoot them both. &lt;/seg&gt;
      &lt;/doc&gt;
      &lt;doc docid="cnn_210092_comment004" articleURL="http://www.cnn.com/News.asp?NewsID=210092" date="06/04/2010" time="17:07" subtitle="Dear Chicago, we love you despite it all" author="MRL1313"&gt;
          &lt;seg id="1"&gt; We can't wait for you to move back either. &lt;/seg&gt;
          &lt;seg id="2"&gt; You seem quite uptight. &lt;/seg&gt;
          &lt;seg id="3"&gt; Does your wife (who is also your sister) not give it up any more? &lt;/seg&gt;
      &lt;/doc&gt;
  &lt;/OnlineCommentary&gt;
  </code></pre>
  
  <p>I would like to to execute command on this file to extract only the contnet between the opening tag <code>&lt;seg ...&gt;</code> and the closing tag <code>&lt;/seg&gt;</code></p>
  
  <p>I tried :</p>
  
  <pre><code>sed -n 's:.*&lt;seg id="1"&gt;\(.*\)&lt;/seg&gt;.*:\1:p' XML-file.xml &gt; output.txt
  </code></pre>
  
  <p>My questions are the following: </p>
  
  <p>-- How can I print all <code>&lt;seg id="*"&gt;</code>?? my command prints only the the content of the first tag (<code>&lt;seg id="*"&gt;</code>)  </p>
  
  <p>-- Is that is there a way that can be used to make for example the <code>&lt;seg id="1"&gt;</code>, <code>&lt;seg id="2"&gt;</code>, <code>&lt;seg id="3"&gt;</code> to be printed in the same line while the tag that include only <code>&lt;seg id="1"&gt;</code> to be printed in separate line?? </p>