How do I remove entire lines that include a certain value?
2
0
Entering edit mode
6.1 years ago
Bweil2 ▴ 10

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 • 1.4k views
ADD COMMENT
2
Entering edit mode
6.1 years ago
GenoMax 141k

Try this:

awk -F ' ' '$8 ~ /1|2|3/ {print $0}' zchloro.txt > result
ADD COMMENT
0
Entering edit mode
6.1 years ago
sacha ★ 2.4k
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}'
ADD COMMENT
1
Entering edit mode

That needs to be

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

Login before adding your answer.

Traffic: 2889 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6