Running sort command on unix

I am writing my own parser for the apache log for my company, and I noticed a performance problem that I cannot explain. I have a 1.2 GB text file log.txt.

Command: sort log.txt is 3 seconds slower than command: cat log.txt | sort

Does anyone know why this is happening?

+3
source share
2 answers

cat file | sortis the useless use of Cat .

The cat's goal is concatenation (or "catenate"). If this is only one file, combining it with nothing is a waste of time, and the process costs you.

It does not take longer. Are you sure your timings are correct?

Please post the output:

time sort file

and

time cat file | sort

.

+4

, sort, :

  • .
  • ( ).
  • ... , .;)

, , ? ..

+1

All Articles