I have a file that looks like this
*TRANSACTION STARTED* [020t CARD INSERTED [020tCARD: *************5845 DATE 01-02-16 TIME 05:45:52 05:46:26 GENAC 1 : ARQC EXTERNAL AUTHENTICATE: NO ARPC 05:46:30 GENAC 2 : AAC 01 FEB 2016 05:47:41 10160021 WITHDRAW FROM XXXXXXXX ? INVALID TRANSCATION ON TERMINAL. ----------------------- [020t 05:47:05 CARD TAKEN [020t 05:47:07 TRANSACTION END [0r(1)2[000p[040qe1w3h162[020t*742*02/01/2016*05:47* *TRANSACTION STARTED* [020t CARD INSERTED [020tCARD: *************2584 DATE 01-02-16 TIME 05:47:27 05:48:00 GENAC 1 : ARQC 05:48:05 GENAC 2 : TC [020t 05:48:16 CARD TAKEN [020t 05:48:22 NOTES PRESENTED 0,0,2,0 01 FEB 2016 05:48:52 10160021 WITHDRAW FROM XXXXXXXX ? AMT GHC40.00 [020t 05:48:31 TRANSACTION END [0r(1)2[000p[040qe1w3h162[020t*743*02/01/2016*05:57* *TRANSACTION STARTED* [020t CARD INSERTED [020tCARD: *************3862 DATE 01-02-16 TIME 05:57:28 01 FEB 2016 05:58:33 10160021 INQUIRY FROM XXXXXXXX90018 AVAIL GHC1260.20 LEDGER GHC1260.20 [020t 05:58:06 CARD TAKEN [020t 05:58:11 TRANSACTION END [0r(1)2[000p[040qe1w3h162[020t*744*02/01/2016*06:43* *TRANSACTION STARTED* [020t CARD INSERTED [020tCARD: *************1972 DATE 01-02-16 TIME 06:43:53 01 FEB 2016 06:44:56 10160021 5029110111271972 4490 4490 INQUIRY FROM XXXXXXXX23013 AVAIL GHC14.28 LEDGER GHC14.28 [020t 06:44:25 CARD TAKEN [020t 06:44:29 TRANSACTION END [0r(1)2[000p[040qe1w3h162[020t*745*02/01/2016*06:56*[/CODE] and need to extract what is between *TRANSACTION STARTED* and TRANSACT +ION END, ignoring all other information, and create a new file for ea +ch range. The new file will contain only <CODE> [020t CARD INSERTED [020tCARD: *************2584 DATE 01-02-16 TIME 05:47:27 05:48:00 GENAC 1 : ARQC 05:48:05 GENAC 2 : TC [020t 05:48:16 CARD TAKEN [020t 05:48:22 NOTES PRESENTED 0,0,2,0 01 FEB 2016 05:48:52 10160021 WITHDRAW FROM XXXXXXXX ? AMT GHC40.00 [020t 05:48:31
this is What I have but it is not working it dose not save the files in the folder
#! /usr/bin/perl/ use warnings; use strict; #file to open my $somefile = "/home/lord-ivan/Soures_Code/Perl/projects/Data/EJDATA. +LOG"; open (my $fh, '<:encoding(UTF-8)', $somefile) or die "Could not open f +ile '$somefile' $!"; print "$somefile open"; #Extract ranges of lines from a file while (<$fh>) { if (/TRANSACTION STARTED/ .. /TRANSACTION END/) { next if /TRANSACTION\s*(STARTED|END)/; print $_; } } my $ofh; my $outputfile = "/home/lord-ivan/Soures_Code/Perl/projects/EJ Transpo +rt/Queue/.txt"; BEGIN {$outputfile= "EJ"}; open ($fh, ">>${$outputfile}.txt", print $fh $_); close($outputfile); $outputfile++;

In reply to Extract ranges of lines from a file, saving each range to a separate file by perlato

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.