Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

How to sum a file of numbers?

Answer:

Assume you have a text file with numbers, one line one number, e.g.

1
2
3
4
5
6
7
8
9
10

You can use the paste and bc command for this tasks.

# paste -sd+ num.txt | bc
55
  1. Give line numbers to a text file
  2. Factor numbers in Linux
  3. Run tasks in parallel with xargs
  4. How to count the number of duplicated lines in a file
  5. How to add line number to a text file?

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>