#!/usr/bin/perl use strict; use warnings; my $tag; my $output; my $fh; my $deletestrings; #open DATA,"$ARGV[0]"; while (<DATA>) { chomp; s/[\cA-\cZ]//g; # To remove control characters #To delete the lines which has {IT} and any lines between {IT} and {SO +URCETAG} if (/\{IT\}/ .. /^\{SOURCETAG\}/) { unless (/^\{(IT|SOURCETAG)\}/) { $deletestrings = $_; $_ = '' if index( $_, "$deletestrings" ) >= 0; } } s/[\\|<]$//g; s/^[\\|<]//g; s/<//g; s/^\s+//g; s/\s+$//g; if(/^{(.*)}$/) { # match {METATAG} line $fh = output($output, $tag, $fh); $output = ""; $tag = $1; } else { # not a {TAG} line next unless($tag); next if(/^\s*$/); s/\\//g; $output .= ($output) ? " $_" : "<$tag>$_"; } } $fh = output($output, $tag, $fh); if($fh) { print $fh "</ROOT>\n"; close($fh); } exit(0); sub output { my ($output, $tag, $fh) = @_; if($output) { if($output =~ m/<SOURCETAG>(.*)/) { if($fh) { print $fh "</ROOT>\n"; close($fh); } open($fh, '>', "$1.xml") or die "$1.xml: $!"; print $fh "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<RO +OT>\n"; } print $fh "$output</$tag>\n"; } return($fh); } __DATA__ ^C^D^V^V^A exit 0543 961017 N S 9702050900 00000000^B{IT} N {SOURCETAG} 9702050900 {ACCESSION} 000000 {DATE} 961017 {TDATE} Thursday, October 17, 1996 {PUBLICATION} EXITO {EDITION} Exito {SECTION} SALUD FAMILIAR {PAGE} 22 {SOURCE} Por Nahyr Acosta. Colaboradora de ¡Exito! {COLUMN} Nuestro hijos. {HEADLINE} EVITE LA ENFERMEDAD PERIODONTAL< AS {LEAD}CTIQUE LA HIGIENE DENTAL PARA CUIDAR SUS ENCà Cuando hace casi + dos años visité a mi dentista para hacerme un chequeo dental , me encontré ante un problema que podía terminar con mi dent +adura. Siempre tuve unos dientes sanos y jamás se me ocurrió pensar que pod +ía perder mis piezas si no tomaba acción inmediata. Me puse en manos del denti +sta y empezamos a trabajar en mis encías.<
This code creates a xml output. But for {LEAD} it doesnot creates the proper tag. For the file when I pass the input file as an command line argument, The output is seen as below.
<SECTION>SALUD FAMILIAR</SECTION> <PAGE>22</PAGE> <SOURCE>Por Nahyr Acosta. Colaboradora de ¡Exito!</SOURCE> <COLUMN>Nuestro hijos.</COLUMN> + AS</HEADLINE> <LEAD>Cuando hace casi dos años visité a mi dentista para hacerme un + chequeo dental , me encontré ante un problema que podía terminar c +on mi dentadura. Siempre tuve unos dientes sanos y jamás se me ocurr +ió pensar que podía perder mis piezas si no tomaba acción inmedia +ta. Me puse en manos del dentista y empezamos a trabajar en mis encà +­as. La descomposición de la comida, la saliva y las bacterias que h +ay en la boca producen una sustancia llamada placa, que se adhiere a +la superficie de los dientes y, si no se limpia diariamente, irrita l +as encías y se endurecen, formando el sarro. Esta sustancia, a su ve +z, se adhiere cada vez más, inflamando las encías y produciendo bol +sas que se llenan con colonias de bacterias. Estas son las que con el + tiempo, causan la enfermedad periodontal. Las bacterias también pro +ducen una sustancia llamada toxina, la cual destruye el hueso.</LEAD>
For {LEAD} it creates the tag but not for HEADLINE

In reply to Re^4: Delete till end of line to another string by Anonymous Monk
in thread Delete till end of line to another string by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.