Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim and wc give different line counts

I have two csv files that give different results when I use wc -l (gives 65 lines for the first, 66 for the second) and when I use vim file.csv and then :$ to go to the bottom of the file (66 lines for both). I have tried viewing newline characters in vim using :set list and they look identical.

I have created the second (which shows one extra line with wc) was created from the first using pandas in Python and to_csv.

Is there anything within pandas that might generate new lines or other bash/vim tools I can use to verify the differences?

like image 966
p-robot Avatar asked Dec 06 '25 07:12

p-robot


1 Answers

If the last character of the file is not a newline, wc won't count the last line:

$ printf 'a\nb\nc' | wc -l
2

In fact, that's how wc -l is documented to work: from man wc

  -l, --lines
          print the newline counts
                    ^^^^^^^^^^^^^
like image 86
glenn jackman Avatar answered Dec 07 '25 19:12

glenn jackman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!