Home > OS >  Best way to check if a CSV file contains only zeros (separated by comma)
Best way to check if a CSV file contains only zeros (separated by comma)

Time:01-14

I want to quickly identify files of this form (shape of the "matrix" can change)

0,0,0,0,0
0,0,0,0,0
0,0,0,0,0
0,0,0,0,0

What is the simplest way of doing it?

CodePudding user response:

Try to match any character other than 0 or , with [^0,]. If that fails, the file only contains zeroes.

if ! grep -q '[^0,]' filename.csv
then
    echo file is all zeroes
fi

CodePudding user response:

You can do

grep -v [0,]*

That will show any lines that don't match the expression.

  •  Tags:  
  • Related