delete a row with a specific value at a certain column

Hi,

I want to delete rows that have 0 at column 4.

The file looks like this:

chr01   13	61	2
chr01   65	153	0
chr01   157	309	1
chr01   313	309	0
chr01   317	469	1
chr01   473	557	0

I want to delete all rows with a 0 at column 4

chr01   13	61	2
chr01   157	309	1
chr01   317	469	1

Thanks

awk '$4 != 0' inputfile

try this

awk -F " " '{ if ( $4 != 0 ) print $0 }' infile

@balajesuri yours is much trimmed :slight_smile:

Few points to observe:

  1. awk already separates the fields based on whitespaces. So, -F " " is really not necessary.
  2. awk follows this: condition {action} by default. So an if-statement can be masked as condition{action} , unless its use is inevitable.
  3. awk prints the current line by default. So print $0 is redundant.
  4. Implementing all the above points you get what is in post #2 above :slight_smile:

Well, to shorten it even more, we can say: :smiley:

awk '$4' inputfile
1 Like