Different command methods to count the total lines in a file

view story

http://www.linuxandlife.com – In this article, we will see different methods to get the count of the total lines in a file. 1. Use the combination of wc and cat This is the simplest method, a piping of cat and wc cat file | wc -l 2. Use grep grep has the '-c' option to count lines when some patterns are matched. To get the pattern of every line, we will use '.*', which means to match anything. grep -c '.*' file 3. Use sed The sed command uses the '=' operator for line numbering. The '$' tells to give the count only for the last line. sed -n '$=' file 4. Use awk With awek, we can use the NR variable (Distributions)