Merge this data
I am trying to merge names in column B that are associated with column A.
So basically for all the columns in column A that have the same group
number, I want to merge the names from column B seperated by a comma and
space to another file.
col A col B
group1 ashlyn
group3 brooke
group2 caleb
group1 cali
group2 darlene
group2 dixie
group3 daniel
group1 edward
group3 ethan
group2 felix
group2 francis
group1 gabriel
to
group1 ashlyn, cali, edward, gabriel
group2 caleb, darlene, dixie, felix, francis
group3 brooke, daniel, ethan
I tried this
open FH, '<', 'file.txt' or die $!;
open FH2, '>', 'file2.txt' or die $!;
@array = <FH>;
foreach $item (@array){
($group, $name) = split/ /, $item;
print FH2 "$group $name";
}
No comments:
Post a Comment