count lines in a file with grep code example Example 1: grep count lines cat myfile | wc -l Example 2: grep count lines wc -l myfile