How to delete all lines from a CSV file containing an exact match of a search term?

awk, bash, sed

Solution

If that's your last field, grep will do the trick:

grep -v ',0$'

If not, and your fields don't contain `,`, use awk:

awk -F , '{if ($2!='0') print}'

If it's even more complex use python or ruby with a CSV parser.

Problem

I have a CSV file like this: ``` text,0 more text,2 some more text,100 ``` I need to delete any line containing only `0` in the second column, e.g., the output of the above would be: ``` more text,2 some more text,100 ``` How can I delete all lines from a CSV with an exact match?

Original source