Search code examples
shellcountwc

Count non blank lines


I am using wc -l to count the number of lines I get as output from docker ps command. Sometimes there are no containers in the list and it just gives empty line but wc -l counts that as well and says the answer as 1. How can I avoid this


Solution

  • try the count option of grep and dot means any character which is not blank.

    docker ps|grep -c .