Suppose I'm given a variety of files, some with line endings of
\r\n. How would I efficiently count the number of lines in a file when I don't know what to expect beforehand?
wc -l won't work if there are Mac line endings.
Grep appears to be very inaccurate when used:
grep -o '\r' /path/to/file.txt | wc -l
Gives 1041 lines but there are actually only 299 lines, and
nano is able to confirm that by auto-converting from Mac format.
It also doesn't provide the versatility I was hoping for because
grep -o '[\r\n]+' /path/to/file.txt | wc -l returns a count of 0.
How do I do this correctly?