gpt4 book ai didi

linux - bash,如何对列的整数值求和?

转载 作者:太空宇宙 更新时间:2023-11-04 11:46:08 24 4
gpt4 key购买 nike

<分区>

我需要找到一种方法来汇总文件中特定列的所有整数值,并打印其结果。这是我的文件的一部分:

<<< The program found 0 rare variants for the gene ARIH1 for this HEALTHY_CONTROL <<<

<<< The program found 0 rare variants for the gene ARIH1 for this HEALTHY_CONTROL <<<

<<< The program found 1 rare variants for the gene ARIH1 for this HEALTHY_CONTROL <<<

<<< The program found 0 rare variants for the gene ARIH1 for this HEALTHY_CONTROL <<<

<<< The program found 0 rare variants for the gene ARIH1 for this HEALTHY_CONTROL <<<

<<< The program found 2 rare variants for the gene ARIH1 for this HEALTHY_CONTROL <<<

<<< The program found 0 rare variants for the gene ARIH1 for this HEALTHY_CONTROL <<<

<<< The program found 0 rare variants for the gene ARIH1 for this HEALTHY_CONTROL <<<

<<< The program found 2 rare variants for the gene ARIH1 for this HEALTHY_CONTROL <<<

<<< The program found 0 rare variants for the gene ARIH1 for this HEALTHY_CONTROL <<<

<<< The program found 1 rare variants for the gene ARIH1 for this HEALTHY_CONTROL <<<

我想打印第 5 列的总和,即稀有变体的总数。在这个例子中,它应该打印 6。

我尝试了以下命令(没有用):

grep "rare variants for the gene ARIH1" fileName | tail -n+2 | awk -F " " '{sum+=$5} END {print sum}'

此命令打印 1,这是错误的。

我该怎么办?谢谢!

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com