Awk delete line that contains data

It should be enough to say

$ awk '$3 != 7'

Note that this a numerical comparison, and will omit lines in which the third field is, for example, "0.7e1", but it will work for the sample data you provide.


delete a line containing 7

awk '!/7/' yourFile

The other answers work. Here's why

Awk's standard processing model is to read a line of input, optionally match that line, and if matched (optionally) print the input. The other solutions use a negation match, so lines are printed unless the match is made.

Your code sample doesn't use a negation match: it says "if something is true, do it". Because you want to delete the input, when you match that target, you can just skip printing it.

{
  if($3 == 7){
     #skip printing this line
     next
  }
}

IHTH.

Tags:

Awk