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