Many thanks for your help but I think to need more help.
I modified the script in this way:

#!/usr/local/bin/perl

my $file = '/home/users/francesco/pippo';
my $outfile = '/home/users/francesco/newpippo';

open(DATA, $file) || die "Non posso aprire il file";
open(OUT, ">$outfile") || die "Non posso aprire il file";

while( <DATA> ) {
  chomp;

if( /(00\d+)/ ) {
    $key = $1;
    next if !/^(ct|ma|mb)/;
  }
  else {
    $key = $_;
  }

  if( exists( $hash{$key} ) ) {
    push @{$hash{$key}}, $_;
  }
  else {
    $hash{$key} = [$_];
  }
}
foreach ( sort keys %hash ) {
  print OUT  join( ', ', @{$hash{$_}} ), "\n";
}

and the output is:

ct000043, ma000043
ct000047
ct000049, ma000049, mb000049
ct000053
ct000061

But I need something a little bit different.For each number I want to write the ct, 
the ma, the mb.And the output wuold be:

ct000043
ct000056
ma000043
ma000056
mb000043
mb000056

I hope to became soon to be able to do this without help but now...
Many thanks another time.Bye

 

Reply via email to