Reputation: 5
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 61
So, I want to calculate from Column (Num1) 34-23, 43-34, 63-43. And same for column(Num2). Can you please help me. I can only calculate the value within rows which is $1 - $2
, but not within column.
Upvotes: 0
Views: 681
Reputation: 14949
You can try this,
awk 'NR==1{col1=$1; col2=$2;} { print $1-col1,$2-col2; col1=$1;col2=$2}' yourfile
Upvotes: 0
Reputation: 753805
Remember the old values (from the previous row).
awk 'NR > 1 { print $1 - old1, $2 - old2 }
{ old1 = $1; old2 = $2 }' data.file
Upvotes: 1