wc -l is NOT counting last of the file if it does not have end of line character
It is better to have all lines ending with EOL \n
in Unix files. You can do:
{ cat file; echo ''; } | wc -l
Or this awk:
awk 'END{print NR}' file
grep -c
returns the number of matching lines. Just use an empty string ""
as your matching expression:
$ echo -n $'a\nb\nc' > 2or3.txt
$ cat 2or3.txt | wc -l
2
$ grep -c "" 2or3.txt
3