Delete line with specific numerical value

text processing

I have a file that looks like this:

AA  110 B   2   ..  BB  3   ... BBB 3   D   F   3   D   D
AA  111 B   2   ..  BB  3   ... BBB 0   F   F   0   F   F
AA  112 C   2   ..  BB  3   ... BBB 0   D   F   0   D   F
AA  120 D   2   ..  FF  3   ... FFF 3   D   F   3   D   D

I would like to remove any line that contain the specific numerical value of 0. If I do:

sed '/0/d' infile > newfile

then lines 1 and 4 are deleted because they contain "0s" in 110 and 120. I tried other options with grep grep -v '0' infile > newfile or awk but no luck.

I'm sure there is a straightforward way for doing this but cannot find it. Any thoughts?

Thanks!

Best Answer

Add -w to grep to do whole-word matching:

$ grep -vw 0 infile 
AA  110 B   2   ..  BB  3   ... BBB 3   D   F   3   D   D
AA  120 D   2   ..  FF  3   ... FFF 3   D   F   3   D   D
Related Question