3

I have the following kind of file separated by tabulations:

75  85
75  84
94  301
89  123
75  75
94  130
94  250
89  210

I need to print the lines where column 2 - column 1 > 80, so, it would look something like:

94  301
94  250
89  210

I've tried to use operators with awk, but I don't know how to do math using awk to print these lines, is there a way to do so?

6

Using awk:

awk '$2 - $1 > 80' file

awk's default action is to print so this is saying if the condition (that column 2 minus column 1 is greater than 80) is met, print that line.

  • 1
    Awesome, it worked! I'll have that in mind when doing this kind of operations, thanks! – Lucas Farinazzo Marques Nov 14 at 19:16
-2

I have tried with below command

awk '{print $1,$2,$2 - $1}' file| awk '$NF > 80 {print $1,$2}'
94 301
94 250
89 210
  • 3
    Why do you split the awk code into two separate awk invocations? – Kusalananda Nov 17 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.