[Question]
  [
Consider a stream/file with one integer per line. For example:
```
123
5
99
```
Your code should output the sum of these numbers, that is `227`.
The input format is strictly one integer per line. You cannot, for example, assume the input is on one line as an array of integers.
You can take input either from STDIN, in form of a filename, or a file with a name of your choice; you can choose which one. No other ways of getting input are allowed.
The input will contain at least one integer. You can assume all integers are non-negative and that their total sum is less than `232`.
  
[Answer]
## Bash + coreutils, 16 bytes
```
xargs|tr \  +|bc
```
**[Try it online!](https://tio.run/nexus/bash#@1@RWJReXFNSpBCjoKBdk5T8/7@hkTGXKZelJQA)**
There are two spaces after the `\`. This works for negative numbers as well.
**Explanation:**
```
xargs             # known trick to turn newlines into spaces, while adding a
                  #trailing newline when printing the result (needed for bc)
|tr \  +          # turn spaces into '+'s
|bc               # calculates the sum
```
You may wonder why `tr \\n +|bc` isn't better, since it turns newlines directly into '+'s. Well, that has 2 unforeseen errors:
* if the input has a trailing newline, then it is converted to a trailing '+', hence there is no number after it to perform the addition
* and the most weird issue is that bc requires a trailing newline after the input, but you just replaced all of the input newlines with '+'s.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 2 bytes
```
|O
```
Explanation:
```
|   Get input as array
 O  Sum
```
[Try it online!](https://tio.run/nexus/05ab1e#@1/j//@/oZExlymXpSUA "05AB1E – TIO Nexus")
[Answer]
# [MATL](https://github.com/lmendo/MATL), 2 bytes
```
Us
```
This expects the input in a text file called `defin`.
*Gif or it didn't happen*:
[![enter image description here](https://i.stack.imgur.com/a2cpD.gif)](https://i.stack.imgur.com/a2cpD.gif)
Or [**try it online!**](https://tio.run/##S0oszvifnFiiYKeQkpqWmfc/P7kksSxVQVe3ILEkQ0E/v6BEPzexJAcokFqWmKOgBOaEFiv9/29oZMxlymVpCQA) (*thanks to Dennis for the set-up!*)
### Explanation
When a MATL program is run, if a file called `defin` is found (the name refers to "default input"), its contents are automatically loaded as text and pushed to the stack as a string before executing the code.
Function `U` evaluates the string to convert it to a column vector of numbers, and `s` computes the sum, which is implicitly displayed.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 2 bytes
```
Nx
```
### Explanation
```
     Implicit: parse STDIN into array of numbers, strings, and arrays
N    Get the resulting parsed array.
 x   Sum.
     Implicit: output result of last expression
```
[Try it online!](https://tio.run/nexus/japt#@@9X8f@/oZExlymXpSUA "Japt – TIO Nexus")
[Answer]
# Paste + bc, 13 bytes
```
paste -sd+|bc
```
Explanation:
```
paste -s        Take one line at a time from input
        d+      Joining by '+'
          |bc   Pass as expression to bc
```
Another shell answer!
[Answer]
# [Perl 6](https://perl6.org), 13 bytes
```
say sum lines
```
[Try it](https://tio.run/nexus/perl6#@19QWqJQXJqrkJOZl1r8/7@hkTGXKZelJQA "Perl 6 – TIO Nexus")
## Explanation
* `lines()` returns a list of lines from `$*IN` or `$*ARGFILES` a “magic” command-line input handle.
* `sum(…)` was added to Perl 6 to allow `[+] List` to be optimized for Positionals that can calculate their sum without generating all of their values like `1..100000`  
(I just thought `sum` was just too cute here to use `[+]` like I normally would)
* `say(…)` call the `.gist` method on its input, and prints it with an additional newline.
[Answer]
# C, 53 bytes
```
r;main(i){for(;~scanf("%d",&i);r+=i);printf("%d",r);}
```
[Answer]
# [Python 3](https://docs.python.org/3/), 28 bytes
```
print(sum(map(int,open(0))))
```
Taken from [this tip](https://codegolf.stackexchange.com/a/70670/12012). I've been told this won't work on Windows.
[Try it online!](https://tio.run/nexus/python3#@19QlJlXolFcmquRm1igAWTr5Bek5mkYaALB//@GRsZcplyWlgA "Python 3 – TIO Nexus")
[Answer]
# [Retina](https://github.com/m-ender/retina), ~~11~~ 7 bytes
-4 thanks to Martin Ender
```
.*
$*
1
```
[Try it online!](https://tio.run/nexus/retina#@6@nxaWixWX4/78hlxGXMZcJlwGXJQA "Retina – TIO Nexus")
---
Convert to unary:
```
.*
$*
```
Count the number of `1`s:
```
1
```
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), 20 bytes
```
(([]){[{}]{}([])}{})
```
[Try it online!](https://tio.run/nexus/brain-flak#@6@hER2rWR1dXRtbXQti1lbXav7/b8hlxGXMZcJlwGXJZQYA "Brain-Flak – TIO Nexus")
## Explanation
This is a golf off of [a solution made by Riley in chat](http://chat.stackexchange.com/transcript/message/36243146#36243146). His solution was:
```
([])({<{}>{}<([])>}{})
```
If your familiar with Brain-Flak this is pretty self-explanatory. It pushes the stack height and pops one value as it counts down, at the end it pushes the sum of all the runs.
It is a pretty good golf but he zeros both `{}` and `([])` however these will have a values that only differ by one so if instead we remove the masks and make one of the two negative they should nearly cancel out.
```
([])({[{}]{}([])}{})
```
Since they always differ by one we have the unfortunate circumstance where our answer is always off by the stack height. In order to remedy this we simply move the beginning of the push to encompass the first stack height.
```
(([]){[{}]{}([])}{})
```
[Answer]
# Python 2, 40 bytes
```
import sys;print sum(map(int,sys.stdin))
```
[Answer]
# [Perl 5](https://www.perl.org/), 9 bytes
8 bytes of code + `-p` flag.
```
$\+=$_}{
```
[Try it online!](https://tio.run/nexus/perl5#U1YsSC3KUdAt@K8So22rEl9b/f@/oZExlymXpSUA "Perl 5 – TIO Nexus")
With `-p`, the input is read one line at a time, stored in `$_` each time. We use `$\` as accumulator, because thanks to `-p` flag, it's implicitly printed at the end. The unmatched `}{` are used so `-p` flag only prints `$\` once at the end instead of printing `$_` and `$\` at each line it reads like it normally does. 
[Answer]
## R,11 bytes
```
sum(scan())
```
`scan` takes the input, one number per line. And `sum`, well, sums.
[Answer]
# Pure Bash, ~~37~~ 36 bytes
*Thanks to @KevinCruijssen for a byte!*
```
while read a;do((b+=a));done;echo $b
```
[Try it online!](https://tio.run/nexus/bash#@1@ekZmTqlCUmpiikGidkq@hkaRtm6ipCWTmpVqnJmfkK6gk/f9vaGTMZcplackFAA "Bash – TIO Nexus")
[Answer]
## Haskell, 32 bytes
```
interact$show.sum.map read.lines
```
[Try it online!](https://tio.run/nexus/haskell#@5@bmJlnm5lXklqUmFyiUpyRX65XXJqrl5tYoFCUmpiil5OZl1r8/7@hkTGXKZelJQA "Haskell – TIO Nexus").
`interact` collects the whole input from stdin, passes it to the function given as its argument and prints the string it gets back from this function. The function is:
```
            lines   -- split input into list of lines at nl
      map read      -- convert every line to a number (read is polymorphic,
                    -- but as want to sum it later, the type checker knows
                    -- it has to be numbers)
    sum             -- sum the list of numbers
show                -- convert back to string
```
[Answer]
# PHP, 22 bytes
```
<?=array_sum(file(t));
```
This assumes there is a file named "t" with a list of integers.
`file()` opens a file and returns an array with each line stored a separate element in the array. `array_sum()` sums all the elements in an array.
[Answer]
# Awk, 19 bytes
```
{s+=$1}END{print s}
```
Explanation:
```
{s+=$1}                For all lines in the input, add to s
        END             End loop
           {print s}    Print s
```
[Answer]
# [dc](https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html), 14 bytes
```
0[+?z2=a]dsaxp
```
[Try it online!](https://tio.run/nexus/dc#@28QrW1fZWSbGJtSnFhR8P@/oZExlymXpSUA "dc – TIO Nexus")
Explanation:
```
 [      ] sa   # recursive macro stored in register a, does the following:
  +            # - sum both numbers on stack
               #   (prints to stderr 1st time since there's only 1)
   ?           # - read next line, push to stack as number
    z          # - push size of stack
     2         # - push 2
      =a       # - if stack size = 2, ? yielded something, so recurse
               # - otherwise end macro (implicit)
0              # push 0 (accumulator)
         d     # duplicate macro before storing it
            x  # Call macro
             p # The sum should be on the stack now, so print it
```
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 5 bytes
```
q~]1b
```
[Try it online!](https://tio.run/nexus/cjam#@19YF2uY9P@/oZExlymXpSUA "CJam – TIO Nexus")
### How it works
```
q     e# Read all input from STDIN.
 ~    e# Evaluate that input, pushing several integers.
  ]   e# Wrap the entire stack in an array.
   1b e# Convert from base 1 to integer.
      e# :+ (reduce by sum) would work as well, but 1b handles empty arrays.
```
[Answer]
# Python, ~~38~~ 30 bytes
```
lambda n:sum(map(int,open(n)))
```
In python, files are opened by `open('filename')` (obviously). They are, however, iterables. Each time you iterate through the file, you get the next line. So map iterates over each list, calling `int` on it, and then sums the resulting list.
Call with the filename as input. (i.e. `f('numbers.txt')`)
8 bytes saved by using `map(int, open(n))` instead of a list comprehension. Original code:
```
lambda n:sum([int(i)for i in open(n)]) 
```
[Answer]
## Mathematica, 19 bytes
Assumes Mathematica's notebook environment.
```
Tr[#&@@@Import@"a"]
```
Expects the input to be in a file `a`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~9~~ 8 bytes
```
ƈFÐ¿FỴVS
```
STDIN isn't really Jelly's thing...
[Try it online!](https://tio.run/nexus/jelly#@3@sw@3whEP73R7u3hIW/P@/oZExlymXpSUA "Jelly – TIO Nexus")
### How it works
```
ƈFÐ¿FỴVS  Main link. No arguments. Implicit argument: 0
  Ð¿      While loop; while the condition returns a truthy value, execute the body
          and set the return value to the result. Collect all results (including 0,
          the initial return value) in an array and return that array.
ƈ           Body: Yield a character from STDIN or [] if the input is exhausted.
 F          Condition: Flatten, mapping 0 to [], '0' to "0", and [] to [] (falsy).
    F     Flatten the result.
     Ỵ    Split at newlines.
      V   Evaluate the resulting strings.
       S  Take the sum.
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 4 bytes
```
ṇịᵐ+
```
[Try it online!](https://tio.run/nexus/brachylog2#@/9wZ/vD3d0Pt07Q/v9fydDImMuUy9JS6X8UAA "Brachylog – TIO Nexus")
### Explanation
```
ṇ         Split the Input on linebreaks
 ịᵐ       Map: String to Integer
   +      Sum
```
[Answer]
# Pure bash, 30
```
read -d_ b
echo $[${b//'
'/+}]
```
[Try it online.](https://tio.run/nexus/bash#@1@UmpiioJsSr5DElZqcka@gEq1SnaSvr86lrq9dG/v/v6GRMZcpl6UlAA)
* `read`s the input file in one go into the variable `b`. `-d_` tells `read` that the line delimiter is `_` instead of `newline`
* `${b//'``newline``'/+}` replaces the newlines in `b` with `+`
* `echo $[ ... ]` arithmetically evaluates the resulting expression and outputs it.
[Answer]
# Vim, 16 bytes/keystrokes
```
:%s/\n/+
C<C-r>=<C-r>"<C-h>
```
Since V is backwards compatible, you can [Try it online!](https://tio.run/nexus/v#@2@lWqwfk6evzeVs46xbZGcLJpWAZIYd1///hlxGXMZcJlwGXBb/dcsA "V – TIO Nexus")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 3 bytes
```
s.Q
```
[Try it online!](https://tio.run/nexus/pyth#@1@sF/j/v6GRMZcpl6UlAA "Pyth – TIO Nexus")
```
 .Q  Read all of standard input, evaluating each line.
s    Take the sum.
```
[Answer]
# [jq](https://stedolan.github.io/jq/), 5 bytes
`add`, plus the command line flag `-s`.
For example:
```
% echo "1\n2\n3\n4\n5" | jq -s add
15
```
[Answer]
# [Actually](https://github.com/Mego/Seriously), 2 bytes
```
kΣ
```
[Try it online!](https://tio.run/nexus/actually#@599bvH//4ZGxlymXJaWAA "Actually – TIO Nexus")
Explanation:
```
kΣ
    (implicit input - read each line, evaluate it, and push it to the stack)
k   pop all stack elements and push them as a list
 Σ  sum
    (implicit output)
```
[Answer]
# dc, 22
```
[pq]sq0[?z2>q+lmx]dsmx
```
This seems rather longer than it should be, but it is tricky to decide when the end of the file is reached. The only way I can think of to do this is check the stack length after the `?` command.
[Try it online](https://tio.run/nexus/dc#@x9dUBhbXGgQbV9lZFeonZNbEZtSnFvx/7@hkTGXKZelJQA).
```
[pq]                    # macro to `p`rint top-of-stack, then `q`uit the program
    sq                  # save the above macro in the `q` register
      0                 # push `0` to the stack.  Each input number is added to this (stack accumulator)
       [         ]      # macro to:
        ?               # - read line of input
         z              # - push stack length to stack
          2             # - push 2 to the stack
           >q           # - if 2 > stack length then invoke macro stored in `q` register
             +          # - add input to stack accumulator
              lmx       # - load macro stored in `m` register and execute it
                  d     # duplicate macro
                   sm   # store in register `m`
                     x  # execute macro
```
Note the macro `m` is called recursively. Modern `dc` implements tail recursion for this sort of thing, so there should be no worries about overflowing the stack.
[Answer]
# Ruby, ~~19~~ 15 bytes
Loving that new `#sum` in Ruby 2.4 :)
```
p$<.sum(&:to_i)
```
This program accepts input from either stdin or any filename(s) given as command line argument
]