wc command on OS X acting weird?

jonasbn on 2003-06-28T12:11:44

I am revisiting an old project where I want to make some statistics on lines of code.

In order to check whether was I was doing was completely crazy I checked the file in question with the wc command. hyperstation ~/Develop/Copenhagen/modules/Metrics/LOC % wc t/LOC.t 41 122 956 t/LOC.t This differs a bit from my Perl code, which says it contains 42 lines... so I tried grep. hyperstation ~/Develop/Copenhagen/modules/Metrics/LOC % grep -c "" t/LOC.t 42 The man page for wc states

A line is defined as a string of characters delimited by a character
So that is probably the reason, but it still annoys me, heh maybe I should entitle this entry, 'Using wc considered harmful', or maybe I just had too much coffee...


wc behavior

ziggy on 2003-06-29T15:56:07

wc's linecount simply counts newlines. By definition, Unix text files should have a newline at the end of the last character. If it doesn't, the last line is "incomplete", and the linecount will be off by one.

At worst, wc will be one line off because the trailing newline is missing. (vi/vim can show a warning about this as well.)