将数组值与哈希进行比较,如果在文件中匹配则删除键
我有 3 列的 .txt
文件。我想将第一列与第二列进行比较,如果第一列中的值出现在第二列中,我想删除第二列和第三列中的该条目(不应修改第一列)。结果应存储在新文件中。
示例输入:
Col 1 Col 2 Col 3
VIBHAR_02293_1 VIBHAR_00819_2 tatatattattata
VIBHAR_00819_2 VIBHAR_00819_4 tattavgaggagag
VIBHAR_00705_3 VIBHAR_00705_7 attaggaccaggat
VIBHAR_00819_4 VIBHAR_02153_9 ccagggattattat
示例输出:
VIBHAR_02293_1 VIBHAR_00705_7 attaggaccaggat
VIBHAR_00819_2 VIBHAR_02153_9 ccagggattattat
VIBHAR_00705_3
VIBHAR_00819_4
我尝试使用以下代码,但它不起作用:
while($line=(<File>))
{
chomp($line);
@F=split('\t',$line);
$hash{$F[1]}=$F[2];
if ($F[0] eq $F[1])
{
# print "$line\n";
delete($hash{keys});
}
}
如果我上面发布的列的格式不好,那么我想只有我的问题就足够了。
I have .txt
file with 3 columns. I want to compare the first with the second column and if values from the first column appear in the second column, I want to delete that entry in the second and third column (first column should not be modified). The result should be stored in a new file.
Example input:
Col 1 Col 2 Col 3
VIBHAR_02293_1 VIBHAR_00819_2 tatatattattata
VIBHAR_00819_2 VIBHAR_00819_4 tattavgaggagag
VIBHAR_00705_3 VIBHAR_00705_7 attaggaccaggat
VIBHAR_00819_4 VIBHAR_02153_9 ccagggattattat
Example output:
VIBHAR_02293_1 VIBHAR_00705_7 attaggaccaggat
VIBHAR_00819_2 VIBHAR_02153_9 ccagggattattat
VIBHAR_00705_3
VIBHAR_00819_4
I tried using following code but it did not work:
while($line=(<File>))
{
chomp($line);
@F=split('\t',$line);
$hash{$F[1]}=$F[2];
if ($F[0] eq $F[1])
{
# print "$line\n";
delete($hash{keys});
}
}
If the format of the columns which I posted above is not good then, only my question is enough I guess.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您真的想“上移”第 2 列和第 3 列中的值吗?
Do you really want to "move up" the values in columns 2 and 3?