count total number of lines grep code example Example 1: grep count lines cat -n myfile Example 2: grep count lines cat myfile | wc -l