I have a tab delimited file with four columns. I would like to grep for the lines that have a specific pattern in column 1, where it says apple M of N. I only want to extract the lines that have the first number matching the second number, or lines that have the first number one less than the second number. In the example below, rows 2, 3, and 5 (not counting the header row) are the ones that fit the pattern.
Col1 col2 col3 col4
apple (XY_012345, apple 6 of 10) 1 12228 12612
apple (XY_678901, apple 5 of 6) 1 12722 13220
apple (XY_234567, apple 2 of 2) 1 18437 24737
apple (XY_890123, apple 8 of 30) 1 24892 29269
apple (XY_456789, apple 12 of 12) 1 35175 35276
grep
doesn't do math; is some other widely-available UNIX tool acceptable?