my @lines; my %seen; while (<DATA>) { chomp; my ($onetwo,$three) = $_=~/(.*)\|(.*)/; if ($seen{$onetwo}) { $lines[$seen{$onetwo} - 1] .= ",$three"; } else { $seen{$onetwo} = push @lines, $_; } } print "$_\n" for @lines; __DATA__ aaa|bbb|ccc ddd|eee|fff ddd|eee|xxxxx hhh|iiii|jjjjjj
In reply to Re: amalgamate similar lines
by Roy Johnson
in thread amalgamate similar lines
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |