Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Help Sorting a CSV File

by dbuckhal (Chaplain)
on Oct 05, 2019 at 05:16 UTC ( [id://11107082]=note: print w/replies, xml ) Need Help??


in reply to Help Sorting a CSV File

maybe?
#!/usr/bin/perl use strict; use warnings; my $file = shift or die; # read csv file... my $hash; open my $fh, "<", $file; my $result = <$fh>; # grab header... while ( my $line = <$fh> ) { # then read rest of file. push @{$hash->{ [ split /,/, $line ]->[1] }}, $line; } $result .= join '', @{$hash->{$_}} for sort keys $hash; print $result; __output__ 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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11107082]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-20 16:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found