You are in "one liner territory", but there is no real reason to do that - quoting rules between O/S's are different - just write a simple program and be done with it:
#!/usr/bin/perl -w use strict; while (<DATA>) { chomp; # deletes line ending, # If this is a file: # Windows, Unix, Old Apple # <CR><LF>, <LF>, <CR> doesn't matter at all # Perl chomp() in text mode handles all that. # allows $zip to be used in future code # as index [3] without having to worry about # the line ending after the zip code... # assign name and city to index [0,2] respectively # using list slice # just split() upon the '|" character. # many dataBsase export formats use '|' as a field separator. # instead of a "," to make the parsing easier. # "John Smith, Sr.", is harder than FIRST|LAST|TITLE #Now to be sure, there are fancy CSV modules that can #handle this complexity, but that does not appear to be #the case required here (commas within quotes can mean #different than the ones outside of quotes). my ($name, $city) = (split /\|/, $_)[0,2]; print "$name",'|',$city,"\n"; } =prints NAME|CITY AAA|STAT BBB|PPOR CCC|TRET =cut __DATA__ NAME|AGE|CITY|ZIP AAA|23|STAT|60001 BBB|34|PPOR|12345 CCC|11|TRET|2345

In reply to Re: Better method to cut columns from delimited file by Marshall
in thread Better method to cut columns from delimited file by stevieb

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.