Tyson
Tyson

Reputation: 6244

Count lines with awk, regardless of line ending style

What's the best way to count the number of line in a file with awk, regardless of line-ending style (DOS/Windows, UNIX, etc.)?

Upvotes: 2

Views: 721

Answers (3)

farhankhwaja
farhankhwaja

Reputation: 159

You can write a script for counting the number of lines, and get the perfect result. The script for the same is available here, Count No. of lines in UNIX which have data

Upvotes: 1

ghostdog74
ghostdog74

Reputation: 342353

do a dos2unix or unix2dos on the file first, before using awk.

Upvotes: 2

Peter
Peter

Reputation: 132207

How about

grep -c '^.*$' filename

Upvotes: 0

Related Questions