1

我有一些代码可以用来在已排序的文件中查找重复项。(受 awk 启发)代码如下所示:

perl -wnla -e 'BEGIN {$previous = -1} $F[1] == $previous ? print $F[1] : $previous = $F[1]' ../VCF/FIN_20.vcf

不幸的是,它给了我一个错误:

Can't modify print in scalar assignment at -e line 1, at EOF
Execution of -e aborted due to compilation errors.

我需要做什么才能让它工作?

附言。该文件看起来像

20  5282284 rs73594467
20  5282299 rs148317959
20  5282336 rs927106
4

1 回答 1

6

只需在最后一条指令周围添加括号:

perl -wnla -e 'BEGIN {$previous = -1} $F[1] == $previous ? print $F[1] : ($previous = $F[1])' 
#                                                                here ___^              ___^

没有它们,就像:

($F[1] == $previous ? print $F[1] : $previous) = $F[1]
于 2013-10-31T08:21:30.943 回答