How to compare the values of a column in awk in a same file and consecutive lines..

I would like to compare the values of 2nd column of consecutive lines of same file in such a way so that if the difference between first value and second value is more than 100 it should print complete line else ignore line.

Input File

PDB 2500
RTDB 123
RTDB-EAGLE 122
VSCCP 2565

Desired Output:

PDB 2500 (i.e. difference between 2500 and 123 is greater than 100 here)
RTDB-EAGLE 122 (i.e. difference between 122 and 2565 is greater than 100 here)

Thanks..

awk 'NR % 2 != 0 {a=$1; b=$2} NR % 2 == 0 {if (b - $2 > 100 || $2 - b > 100){print a,b}}' inputfile
1 Like

Another one:

awk '{p=$0; v=$2; getline; d=$2 - v} d > 100 || d < -100 {print p}' file
1 Like
awk 'NR > 1 {
  x = s - $2
  if ((x > 0 ? x : -x) > 100)
    print f, s
  }
{ 
  f = $1; s = $2 
  }' infile
1 Like

And another one:

awk '($2-p)^2>10000 && s{print s}{s=$0;p=$2}' infile
1 Like