Macos – cat wc -l count lines line with defined line endings (e.g Mac OS X specific)

bashcatmacosunix

As any command-line user I sometimes want to count lines in text file with well known command:

cat some_text_file | wc -l

I face the problem on Mac OS X, which as far I have it studied is connected with different line endings (sometimes I have output from Mac OS X version of Excel which uses OS X specific line ending, which is not understandable for wc -l; After changin line endings to UNIX style e.g in SublimeText everything works as expected).

SO MY QUESTION:

Can I pass somehow to wc -l the line ending kind as somee parameter which should be used? If yes please provide some example.

Best Answer

Try

cat some_text_file | tr "\r" "\n" | wc -l
Related Question