0

Print lines only if the difference between column 2 values is 10000 or greater

Input File

1   176506  C
1   176566  T
1   188778  C
1   189699  M
1   199878  T
1   259923  H
1   268859  C
1   346868  J
1   349825  K
1   356882  U
1   396293  L

Output

1   176506  C
1   188778  C
1   199878  T
1   259923  H
1   346868  J
1   356882  U

Thanks.

3

1 Answer 1

0

I assume your values are increasing and that you want to print a line if the difference between the last-printed-line and the current line exceeds a threshold:

awk -v n=10000 '$2 - p >= n { print; p = $2 }' infile

Output:

1   176506  C
1   188778  C
1   199878  T
1   259923  H
1   346868  J
1   356882  U
1   396293  L
2
  • I tried this method but it was not working, the input i have shown here is part of a big file, i have edited my input file with some more entries and from that using the command given here it should print line "1 356882 U", but it is skipping that line and printing "1 396293 L" and hence all following entries are changed, can you please explain the possible reason for the same. Aug 2, 2017 at 12:21
  • Does it work now?
    – Thor
    Aug 2, 2017 at 13:50

Not the answer you're looking for? Browse other questions tagged .