There are utilities available outside of Perl that can do what the OP is asking about: *nix sort (which can do multi-field/multi-key sorting and may be able to handle very large files), head, tail and cat. These are also available as "Unix utilities for Windows", which is what I'm using, but you'll have to Google for an appropriate package of these binaries. Here's a Windows command-line session using your OPed example .csv file (BTW: Code tags should be used for input/output and data as well as code):

c:\@Work\Perl\monks\NorthernFox>type 11107044.csv CAT_HEADER,SUPPLIER_CODE,CUSTOMER_CODE CAT_LINE,0001P,ABC12345,20190924,,1,Z,3.36 CAT_LINE,0002P,ABC12345,20190924,,1,Z,3.36 CAT_LINE,0001P,ABC23456,20190924,,1,Z,2.24 CAT_LINE,0002P,ABC23456,20190924,,1,Z,2.24 CAT_LINE,0001P,ABC34567,20190924,,1,Z,2.24 CAT_LINE,0002P,ABC34567,20190924,,1,Z,2.24 c:\@Work\Perl\monks\NorthernFox>head --lines=1 11107044.csv > headlin +e.csv c:\@Work\Perl\monks\NorthernFox>tail --lines=+2 11107044.csv | sort -k + 2 - > sortedbody.csv c:\@Work\Perl\monks\NorthernFox>cat headline.csv sortedbody.csv > sor +ted.csv c:\@Work\Perl\monks\NorthernFox>type sorted.csv CAT_HEADER,SUPPLIER_CODE,CUSTOMER_CODE CAT_LINE,0001P,ABC12345,20190924,,1,Z,3.36 CAT_LINE,0001P,ABC23456,20190924,,1,Z,2.24 CAT_LINE,0001P,ABC34567,20190924,,1,Z,2.24 CAT_LINE,0002P,ABC12345,20190924,,1,Z,3.36 CAT_LINE,0002P,ABC23456,20190924,,1,Z,2.24 CAT_LINE,0002P,ABC34567,20190924,,1,Z,2.24
I'm sure someone with more shell-fu than I can pipe this all together into a one-liner, and you can always put it into a shell script.


Give a man a fish:  <%-{-{-{-<


In reply to Re: Help Sorting a CSV File by AnomalousMonk
in thread Help Sorting a CSV File by NorthernFox

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.