count number of lines using grep code example Example 1: grep count lines grep -c ^ filename Example 2: grep count lines cat myfile | wc -l