I need to find the difference between two adjacent columns. The file is having 'i' columns and i need to find the difference between two adjacent columns (like $1 difference $2; $2 difference $3; .... and $(i-1) difference $i). I have used the following coding
awk '{ for (i=1; i<NF; i++) if (($i - $i+1) > 10) print 1; else print 0}' input > output
While using the above in the command line, i am getting the values only in the first column of the output file. I need to print the difference in columns.
(for example; output $1 = input $1 difference input $2...etc..)
The problem here is, i need to get the difference between the two adjacent columns (for example: if the first column first element is 10 and the second column first element is 40, then $1 - $2 = -30, which is less than 10, so the output will be 0 in this case) But if you see the difference is 30. So i need to check the difference is > 10 or not.
Is there any difference operator in awk? (like $1 ~ $2).
I need your help in this regard.
Thank you very much for your prompt reply. I have tried with the following code, but i couldn't get the output as columns, it giving me output in a single column.
Can you suggest some other way to get it?
I need the output in the same format (new_column1=col1 diff col2 (0 or 1), new_column2=col2 diff col3 (0 or 1), etc....)