VDC
VDC

Reputation: 1449

How to delete a line in bash (awk) with 2 conditions

i ve the following problem: I have a file like:

1 3 4
2 5 6
3 1 3
4 1 0
5 7 0
6 0 1

and I would like to delete a line that contains in the second column 1 and in the third one the number 0. So the result should be:

1 3 4
2 5 6
3 1 3
5 7 0
6 0 1

I've tried with: awk '$2!=1 && $3 != 0' file

but it will delete also the lines: '5 7 0' and '3 1 3'

Any help?

Upvotes: 3

Views: 2863

Answers (4)

NawaMan
NawaMan

Reputation: 25687

Try this

awk '$2$3!="10"' file

Cheers!

Upvotes: 0

P.P
P.P

Reputation: 121357

This will ensure that:

 awk '!($2==1 && $3==0){print}' file

i.e. print all lines except those with 2nd column is 1 and 3rd is 0.

Upvotes: 2

William Pursell
William Pursell

Reputation: 212218

You want:

awk '!( $2==1 && $3 == 0)' file

or, equivalently:

awk '$2 != 1 || $3' file

Upvotes: 6

Fred Foo
Fred Foo

Reputation: 363517

You're looking for the negation of $2 == 1 && $3 == 0. By the rules of logic, that's

awk '$2 != 1 || $3 != 0'

Upvotes: 3

Related Questions