My CSV file is delimited by tab, and I want to filter out those rows that have all entries (in 16 columns) of 0 value. I am now doing this
awk '$1 != 0 && $2 != 0 && ....omitted && $16 != 0 {print $0}' file.csv > newFile.csv
As you can see this is so tiring for inputing the same conditions for all 16 columns. Is there any easier way?
What about something like
grep -Ev '^0+([[:space:]]+0+){15}$' file.csv
or
awk --posix '!/^0+([[:space:]]+0+){15}/'
How about something like this (assuming you have 16 fields throughout)
awk '{for (i=1; i<=16; ++i) if($i != 0) {print;next}}' file.csv > newFile.csv
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With