If you want to remove any text up to and including the first comma you could do this.

$ perl -Mstrict -Mwarnings -e ' open my $inFH, q{<}, \ <<EOD or die $!; L1,830 HORIZON PKG RELEASE L2, L3,PURPOSE:,00,RELEASE #,746962464,SCHEDULE TYPE:,PR, L4,SCH QTY TYPE:,A, L5, L6,HORIZON START:,20140915 L7,END:,20150913 L8,GENERATION DATE:,20140915 L9, L10,SHIP TO NAME:,, L16,SHIP TO CODE:,US08, L15, DETAIL,BUYERS PART #,QUANTITY,FCST TYPE,FCST TIMING,DATE, DETAIL,1070954,6000,PLANNING(D),DISCREET(D),20140925SMS,10, DETAIL,1070954,10000,PLANNING(D),DISCREET(D),20140926SMS,10, EOD while ( <$inFH> ) { s{^[^,]*,}{}; print } close $inFH or die $!;' 830 HORIZON PKG RELEASE PURPOSE:,00,RELEASE #,746962464,SCHEDULE TYPE:,PR, SCH QTY TYPE:,A, HORIZON START:,20140915 END:,20150913 GENERATION DATE:,20140915 SHIP TO NAME:,, SHIP TO CODE:,US08, BUYERS PART #,QUANTITY,FCST TYPE,FCST TIMING,DATE, 1070954,6000,PLANNING(D),DISCREET(D),20140925SMS,10, 1070954,10000,PLANNING(D),DISCREET(D),20140926SMS,10, $

If you ony want to remove the particular fields you mention in your code then you can construct a regex with alternation.

$ perl -Mstrict -Mwarnings -e ' open my $inFH, q{<}, \ <<EOD or die $!; L1,830 HORIZON PKG RELEASE L2, L3,PURPOSE:,00,RELEASE #,746962464,SCHEDULE TYPE:,PR, L4,SCH QTY TYPE:,A, L5, L6,HORIZON START:,20140915 L7,END:,20150913 L8,GENERATION DATE:,20140915 L9, L10,SHIP TO NAME:,, L16,SHIP TO CODE:,US08, L15, DETAIL,BUYERS PART #,QUANTITY,FCST TYPE,FCST TIMING,DATE, DETAIL,1070954,6000,PLANNING(D),DISCREET(D),20140925SMS,10, DETAIL,1070954,10000,PLANNING(D),DISCREET(D),20140926SMS,10, EOD my @removes = map { q{L} . $_ } 1 .. 12, 14 .. 16; push @removes, qw{ DETAIL SPACE SUMMARY }; my $qrRemove = do { local $" = q{|}; qr{^(?:@removes),}; }; while ( <$inFH> ) { s{$qrRemove}{}; print } close $inFH or die $!;' 830 HORIZON PKG RELEASE PURPOSE:,00,RELEASE #,746962464,SCHEDULE TYPE:,PR, SCH QTY TYPE:,A, HORIZON START:,20140915 END:,20150913 GENERATION DATE:,20140915 SHIP TO NAME:,, SHIP TO CODE:,US08, BUYERS PART #,QUANTITY,FCST TYPE,FCST TIMING,DATE, 1070954,6000,PLANNING(D),DISCREET(D),20140925SMS,10, 1070954,10000,PLANNING(D),DISCREET(D),20140926SMS,10, $

I hope this is helpful.

Cheers,

JohnGG


In reply to Re: Removing everything before the first comma separator on each line of a text file by johngg
in thread Removing everything before the first comma separator on each line of a text file by zodell

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.