I have a file like this :
# cat list
cucm, location,76,2
cucm1,location1,76,4
cucm,location,80,8
cucm1,location1,90,8
cucm1,location1,87,11
cucm,location,67,9
and I want output like this :
cucm,location,76,2
cucm1,location1,76,4
cucm,location,80, 6 ===> (8-2 =6)
cucm1,location1,90,4 ====>(8-4=4)
cucm1,location1,87,3
cucm,location,67,1
Only when the first and second column matches, I should take a difference of fourth column in the consecutive matching rows.
How will I achieve it. ?
I tried this :
awk -F"," '/cucm1,location1/ {print $1, $2, $3, $4, $4-prev;prev=$4;}' list
This works. But i may not know the contents in the runtime. Hence it has to check if column1 and column2 matches and then do a diff.
Please help