liujiaxin2018

1、测试数据

[root@centos7 test]# cat a.txt
4
8
2
6

 

2、直接求和

[root@centos7 test]# awk \'{sum += $1}END{print sum}\' a.txt
20

 

3、累积求和

[root@centos7 test]# cat a.txt
4
8
2
6
[root@centos7 test]# awk \'{sum += $1}{print sum}\' a.txt
4
12
14
20

 

4、在前一行和的基础上递增下一行的1/2

[root@centos7 test]# paste -d " " a.txt <(cat <(awk \'NR ==1 {print $0/2}\' a.txt) <(awk \'{sum+=$1}{print sum}\' a.txt | sed \'$d\'))| awk \'{print $0,$2 + $1/2}\'
4 2 4
8 4 8
2 12 13
6 14 17

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-11-28
  • 2021-07-27
  • 2021-12-28
  • 2021-12-27
  • 2021-11-28
  • 2021-12-15
  • 2022-02-15
猜你喜欢
  • 2022-02-11
  • 2021-12-10
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
相关资源
相似解决方案