0

file1.txt の列 2 (NAN/0 の場合) の内容を column1 の内容に置き換えたい:

これは私の入力 file1.txt です:

 file for parsing
 mnot   NAN
 PU1     0
 PU2     ets
 munt    tsu
 PU3    ttsm
 munt2    0

必要な出力ファイルは次のとおりです。

file for parsing
mnot   mnot
PU1    PU1
PU2    ets
munt   tsu
PU3    ttsm    
munt2  munt2

私のコード(以下)は正しい出力を与えていません:

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

open(IN, "<", "file1.txt") or die "Can't open file for reading:$!";

my $header = <IN>;
print OUT $header;


while (<IN>){
chomp;
my @sections = split(/\t/);
$sections[0] = 0;
$sections[1] = 0;

if (($sections[1] eq 'NAN') || ($sections[1] == 0)) {
    print OUT $sections[0], "\t", $sections[1], "\n";
    #print OUT "$sections[0]\n";
    }   
else {
    print OUT $sections[0], "\t", $sections[1], "\n";
    #print OUT "$sections[2]\n";
    }
 }

助けてください!

4

1 に答える 1