in reply to Help Sorting a CSV File

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:  <%-{-{-{-<