Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 1
    My gut reaction is it has to do with buffering. Commented Aug 20, 2012 at 22:52
  • 2
    @bahamat I think you're right. The echo does a separate write() for each argument. The sed buffers them. So the first version has a million writes to a regular file, going through a filesystem driver into the block device layer, and the second version has a million writes going into a pipe and somewhat fewer writes going through the more expensive layers of kernel code. Commented Aug 20, 2012 at 23:03
  • 1
    @bahamat Definitely buffering. time echo ... |cat >file and even time echo ... |perl -ne 'print' are similar times to the sed version. Commented Aug 20, 2012 at 23:08
  • 5
    Thanks to everyone for the good explanations... So for big multi-line writes (in bash), cat has gained a Useful Use of Cat point :) Commented Aug 21, 2012 at 0:03