in reply to sorting comma separated value file
I would start by creating a hash with the keys of the hash equivalent to the values of the column you are sorting on.
Use the desired field for the hash key (the ".=" covers multiple keys of the same name (tho not sorting them later))
foreach my $line (@file) { chop ($line); $line =~ s/ //g; my @values = split (/,/, $line); $thehash{$values[$field]} .= "$line\n"; }
Once the hash is created, sort it and print it:
@keys = sort(keys %thehash); foreach (@keys) { print "$thehash{$_}"; }
This will cover having two identical key values, but
will not sort them appropriately (at least in my mind)
e.x.- (sorted on first field, it doesn't look to the second field for more clarification)
99,bbbc,5fa3aaa
99,ccc,2143
It will only sort the actual field specified.
I leave fixing that to the reader.
Then again you could just put the data into a database and use SQL.
|
|---|