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*

5
  • 2
    This ones works with mac OS 10.15 Commented Apr 7, 2020 at 19:31
  • 4
    command | paste -s -d'+' - | bc that one works on mac OS too Commented Jul 25, 2021 at 17:22
  • On my system (Ubuntu 20.04) the command with nawk is about twice faster than with gawk (default awk), and about x3 faster than the winner paste|bc command.. Tested with the 1..49999998 file. Commented Jul 11, 2022 at 6:39
  • command | paste -s -d'+' - | bc works also on AIX. :) Commented May 24, 2024 at 9:37
  • Upvoting, though the expression in @gbgnv's comment under ghostdog74's answer is better solution for empty stream. I needed to return 0 when stream is empty. Commented Dec 19, 2024 at 13:45