Awk command - calculation of columns

后端 未结 2 1524
旧巷少年郎
旧巷少年郎 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
    
    0 讨论(0)
  • 2021-01-28 15:14

    You can try this,

    awk 'NR==1{col1=$1; col2=$2;} { print $1-col1,$2-col2; col1=$1;col2=$2}' yourfile
    
    0 讨论(0)
提交回复
热议问题