1

I have a very large file. What would be the fastest way to get the line count. Here are some options I considered:

wc -l file.txt

sed -n '$=' file.txt

For a large file (100GB or larger), what would be the fastest way?

David542
  • 104,438
  • 178
  • 489
  • 842

1 Answers1

2

Here's an interesting discussion about the different options. Benchmarks copied here:

0.024 sec (avg) - wc -l file.txt
0.121 sec (avg) - sed -n '$=' file.txt
0.396 sec (avg) - nl file.txt | tac |sed -n 1p | awk '{print $1}

Run on a 18 Mb - 500,000 line file.

nathancahill
  • 10,452
  • 9
  • 51
  • 91