This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How do I remove entire lines that include a certain value?

How do I remove entire rows that contain either a 4 or a 5 in the rightmost column? I only want 1, 2, or 3 values in that column.

head zchloro.txt

Zm00001d000199|Zm000   96   0.848  0.114  0.050  0.146   C    2
Zm00001d000199|Zm000  340   0.764  0.088  0.050  0.279   C    3
Zm00001d000200|Zm000  111   0.892  0.608  0.000  0.004   C    4
Zm00001d000200|Zm000  113   0.856  0.559  0.000  0.006   C    4
Zm00001d000204|Zm000   85   0.468  0.360  0.028  0.201   C    5
Zm00001d000230|Zm000  309   0.718  0.682  0.002  0.026   C    5
Zm00001d000232|Zm000 1169   0.478  0.301  0.004  0.188   C    5
Zm00001d000236|Zm000  557   0.522  0.301  0.008  0.139   C    4
Zm00001d000254|Zm000  118   0.577  0.262  0.000  0.158   C    4
Zm00001d000256|Zm000  227   0.633  0.072  0.044  0.574   C    5
genome gene alignment

2 answers

Try this:

awk -F ' ' '$8 ~ /1|2|3/ {print $0}' zchloro.txt > result
cat yourfile.txt|grep -wEv "4|5"

w : word
E : regexp
v : remove line

Or using awk :

   cat yourfile.txt|awk '$8 !~ "4|5" {print $0}'

That needs to be

cat yourfile.txt|grep -wEv "4$|5$"

Log in to answer this question.