Hi Anamika,

Please, check my comments and suggestion below:
On Wed, Apr 4, 2012 at 1:57 PM, Anamika K <anamika...@gmail.com> wrote:

> Hello All,
> I have a file like this:
>
>
> NM_009648,NM_001042541:1        0.955794504181601
> NM_019584:1     0.900900900900901
> NM_198862:1     0.835755813953488
> NM_001039093,NM_001039092,NM_153080:1   0.805008944543828
>
> and want output like this:
>
> NM_009648  0.955794504181601
> NM_001042541:1  0.955794504181601
> NM_019584:1     0.900900900900901
> NM_198862:1     0.835755813953488
> NM_001039093  0.805008944543828
> NM_001039092   0.805008944543828
> NM_153080:1  0.805008944543828
>
> I am using split function first to separate column 1 with column 2 and
> then  based upon "comma" I need to split column 1. But as you can see,
> in the column 1, there are sometimes more than two patterns separated
> by comma, so I am unable to do it in a correct way.
>
>    Fine, you showed your data and the output you want but you could as
well show want  you have done so far, so that people in the list could
help. Check my suggestion below and see if that could help in any way.

> Could you please suggest my how to proceed?
> Thanks.
>
>   This is one possible way of doing what you want:

#!/usr/bin/perl
use warnings;
use strict;

 my %rec;

    while(<DATA>){
      my @arr=split/,|\s+/,$_;
       my $last=pop @arr;
      for (@arr){
         $rec{$_}= $last;
       }
    }

   print $_,'  ',$rec{$_},$/ for keys %rec;
__DATA__
NM_009648,NM_001042541:1        0.955794504181601
NM_019584:1     0.900900900900901
NM_198862:1     0.835755813953488
NM_001039093,NM_001039092,NM_153080:1   0.805008944543828

**OUTPUT**

NM_001039092  0.805008944543828
NM_153080:1  0.805008944543828
NM_009648  0.955794504181601
NM_198862:1  0.835755813953488
NM_001039093  0.805008944543828
NM_019584:1  0.900900900900901
NM_001042541:1  0.955794504181601



-- 
Tim

Reply via email to