linux 中awk命令实现每隔指定行数输出平均值

 

001、

[root@pc1 test01]# ls
a.txt
[root@pc1 test01]# cat a.txt       ## 测试数据
40
60
20
40
40
80
60
20
20
0
0
80
4
4
8
8                                    ## 每隔4行输出平均值
[root@pc1 test01]# awk '{sum += $0; if(NR % 4 == 0) {print sum/4; sum = 0}}' a.txt
40
50
25
6

 。

 

posted @ 2023-10-06 10:45  小鲨鱼2018  阅读(47)  评论(0编辑  收藏  举报