gives the result without the filename, because wc is reading from stdin.
{n++} - for every line read from input, add one to n. The first time n is encountered it is assumed to be zero.
END{} runs after all of the lines in the file have been read.
FYI. If you happen to have a file with out an EOL (newline) as the last line of the file, it is not included as part of the count. The awk command will include the last line regardless of terminator.
And to find the number of lines in a file requires reading the entire file.
So pick the tool and code you think applies. In UNIX there are usually several ways to do one thing.
I'm well aware of the "useless use of cat". I am not arguing that chittari's solution is the best (in fact, I find it evil; I would use jim's solution), but it could be an acceptable solution for some people. In this thread, jim also said, "So pick the tool and code you think applies. In UNIX there are usually several ways to do one thing."