我希望将 file1.txt 中第 2 列(当 NAN/0)的内容替换为第 1 列的内容:
这是我的输入 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";
}
}
请帮忙!