I have been using wc -l
to check for the number of lines exist in my files. It worked fine always but not this time.
I have 120 big files that are supposed to have at least two lines in each of them. I have just done some text editing work on those files to remove and add new lines. I was trying to check the final number of line by using wc -l *
as usual. The output showed that most of the files had only one line.
I opened up one of the file (which showed from the result of the command that it had only one line) with vim
and I can see that it had exactly 2 lines. Exit vim
and check again using wc -l
, the number of line for that file then appeared as 2.
Does anyone have any idea with what happened over here? And how can I solve this problem instead of opening all 120 files with vim
?
PS: The final line of my files weren't empty.
wc -l
command doesn't show precise line number for my files here. But it was corrected only after I tried editing the file usingvim
– web Nov 24 '19 at 7:16[noeol]
at the bottom when you first open one of these files with the editor? – Kusalananda♦ Nov 24 '19 at 8:36wc -l
sincewc -l
counts newlines. – Kusalananda♦ Nov 24 '19 at 9:20wc
program does (it doesn't count "lines" it counts newline characters) or you need to fix your files so they end with newline characters. I give a couple of ways of how to do that in my answer. – icarus Nov 24 '19 at 9:57