0

I'm following this text about another Linux command not related to my question. So I have file1.txt with the following content:

geek
for
geeks

If I use cat -n file1.txt I have the following as output:

1  geek
2  for
3  geeks%    

It counts 3 lines. Great! The way it should be.

But if I use wc -l file1.txt the following shows up:

2 text1.txt

Strange! Why 2 lines?

When I use awk 'END {print NR}' text1.txt (as a suggestion in an answer to a similar - but not equal - question) the output is:

3

Again, 3 lines as it should be.

Clearly I know that the file has 3 lines. So, what is the reason (or reasons) for those commands evoke different outputs?

Browse other questions tagged or ask your own question.