One thing is certain as mentioned by other perlmonks before now that one need know how the OP input file is formatted.
Please see if the below codes gives some light.
Using the OP dataset just as was given and using perl split like thus:
Secondly, since your input is a CSV file, it is better you use module like Text::CSV or Text::CSV_XS.use warnings; use strict; my $l = 'abc,2,3,4,5,6 abc,7,5,2,1,6,2,3 abc,8,2,1,3,1,4 ....... def,8 +,9,4,5,6 def,5,6,2,1 '; my %hash; my $k; for (split/[,. ]+/ => $l){ if(/\D+?/){ $k = $_ }else{ push @{$hash{$k}},$_ } } print $_,',',join (',' => @{$hash{$_}}),$/ for sort keys %hash;
#!/usr/bin/perl use warnings; use strict; use Text::CSV; use Data::Dumper; my %hash; my $csv = Text::CSV->new( { binary => 1 } ) or die "can't use CSV" . Text::CSV->error_diag(); while ( my $row = $csv->getline(*DATA) ) { push @{ $hash{ shift @$row } }, @$row; # as previously mentioned + by Eily } $csv->eof or $csv->error_diag(); print Dumper \%hash; __DATA__ abc,2,3,4,5,6 abc,7,5,2,1,6,2,3 abc,8,2,1,3,1,4 def,8,9,4,5,6 def,5,6,2,1
In reply to Re^3: Combining multiple lines based on the given condition
by 2teez
in thread Combining multiple lines based on the given condition
by anony
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |