系统相关
首页 > 系统相关> > linux 中awk命令计算同一列相邻上数值的差

linux 中awk命令计算同一列相邻上数值的差

作者:互联网

 

001、

root@DESKTOP-1N42TVH:/home/test5/test/test# ls
a.txt
root@DESKTOP-1N42TVH:/home/test5/test/test# cat a.txt
1570051
1570053
5188621
5178672
5188703
5178724
5188900
5178925
5188932
5179705
root@DESKTOP-1N42TVH:/home/test5/test/test# awk 'BEGIN {tmp = 0} {print $NF - tmp; tmp = $NF}'  a.txt
1570051                                   ## 计算相邻两个数的差
2
3618568
-9949
10031
-9979
10176
-9975
10007
-9227
root@DESKTOP-1N42TVH:/home/test5/test/test# awk 'BEGIN {tmp = 0} {print $NF - tmp; tmp = $NF}'  a.txt | sed '1c 0'
0
2
3618568
-9949
10031
-9979
10176
-9975
10007
-9227

 

标签:tmp,1N42TVH,DESKTOP,相邻,awk,linux,test,home,txt
来源: https://www.cnblogs.com/liujiaxin2018/p/16492495.html