Awk command - calculation of columns

后端 未结 2 1562
旧巷少年郎
旧巷少年郎 2021-01-28 14:56

I am very new in Awk. I want to calculate the difference between first row column2 and second row column2. For instance:

Num1 Num2 
23   26
34   39
43   58
63           


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-28 15:13

    Remember the old values (from the previous row).

    awk 'NR > 1 { print $1 - old1, $2 - old2 }
                { old1 = $1; old2 = $2 }' data.file
    

提交回复
热议问题