title: Convert .sgm to .txt
body: <p>I have some files in .sgm format and I have to evaluate them (apply a language model and obtain the perplexity of the text). </p>
  
  <p>The main problem is that I need these files in plain format, i.e. in txt format. However I have been searching into the internet for an online convert or for somekind of script doing this and could not find.</p>
  
  <p>Besides this, a teacher of mine sent me this command in perl:</p>
  
  <pre><code>perl -n 'print $1."\n" if /&lt;seg[^&gt;]+&gt;\s*(.*\S)\s*&lt;.seg&gt;/i;’ &lt; file.sgm &gt; file
  </code></pre>
  
  <p>I have never worked using perl and have, honestly, no idea of it. I think I have perl installed:</p>
  
  <pre><code>$ perl -v
  
  This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thread-multi-2level
  (with 2 registered patches, see perl -V for more detail)
  
  Copyright 1987-2013, Larry Wall
  
  Perl may be copied only under the terms of either the Artistic License or the
  GNU General Public License, which may be found in the Perl 5 source kit.
  
  Complete documentation for Perl, including FAQ lists, should be found on
  this system using "man perl" or "perldoc perl".  If you have access to the
  Internet, point your browser at http://www.perl.org/, the Perl Home Page.
  </code></pre>
  
  <p>By the way, I am using Mac OS X.</p>
  
  <p>Sample .sgm file:</p>
  
  <pre><code>&lt;srcset setid="newsdiscusstest2015" srclang="any"&gt;
  &lt;doc sysid="ref" docid="39-Guardian" genre="newsdiscuss" origlang="en"&gt;
  &lt;p&gt;
  &lt;seg id="1"&gt;This is perfectly illustrated by the UKIP numbties banning people with HIV.&lt;/seg&gt;
  &lt;seg id="2"&gt;You mean Nigel Farage saying the NHS should not be used to pay for people coming to the UK as health tourists, and saying yes when the interviewer specifically asked if, with the aforementioned in mind, people with HIV were included in not being welcome.&lt;/seg&gt;
  &lt;seg id="3"&gt;You raise a straw man and then knock it down with thinly veiled homophobia.&lt;/seg&gt;
  </code></pre>
  
  <p>Otuput .txt file:</p>
  
  <blockquote>
    <p>  <p> This is perfectly illustrated by the UKIP numbties banning
    people with HIV. You mean Nigel Farage saying the
    NHS should not be used to pay for people coming to the UK as health
    tourists, and saying yes when the interviewer specifically asked if,
    with the aforementioned in mind, people with HIV were included in not
    being welcome. You raise a straw man and then knock
    it down with thinly veiled homophobia.</p>
  </blockquote>