Hi all,
I want to compare first line with next line of a file containg single column. for example a file cotains:
NM_1
NM_1
NM_1
NM_2
NM_2
NM_3
NM_4
NM_5
NM_5
NM_5
NM_5
i want to get output as
1 NM_1
2 NM_1
3 NM_1
1 NM_2
2 NM_2
1 NM_3
1 NM_4
1 NM_5
2 NM_5
3 NM_5
4 NM_5
separated by tabs.
Can anybody help me to write perl script to get the above output giving an input file. It will be well appreciated.
But I have written the code as follows. I could not find where to correct my script:
#!/usr/bin/perl
$file=$ARGV[0];
open(INFILE,"$file");
$i = 1;
while(<INFILE>){
chomp;
$currentline = <INFILE>;
print "$i\t $currentline";
$nextline = <INFILE>;
if ($currentline == $nextline ){
$i++;
print "$i\t $nextline";
}
else{
print "1\t $nextline";
$i = 1;
}
}
close(INFILE);
With Regards,
Aeolus
I want to compare first line with next line of a file containg single column. for example a file cotains:
NM_1
NM_1
NM_1
NM_2
NM_2
NM_3
NM_4
NM_5
NM_5
NM_5
NM_5
i want to get output as
1 NM_1
2 NM_1
3 NM_1
1 NM_2
2 NM_2
1 NM_3
1 NM_4
1 NM_5
2 NM_5
3 NM_5
4 NM_5
separated by tabs.
Can anybody help me to write perl script to get the above output giving an input file. It will be well appreciated.
But I have written the code as follows. I could not find where to correct my script:
#!/usr/bin/perl
$file=$ARGV[0];
open(INFILE,"$file");
$i = 1;
while(<INFILE>){
chomp;
$currentline = <INFILE>;
print "$i\t $currentline";
$nextline = <INFILE>;
if ($currentline == $nextline ){
$i++;
print "$i\t $nextline";
}
else{
print "1\t $nextline";
$i = 1;
}
}
close(INFILE);
With Regards,
Aeolus
Comment