Skip to content
Advertisement

more than one source of data to process with bc

I have this file that contains number in a column:

[root@server1]# cat numbers.txt
30
25
15

I need to add them together so I do this:

[root@autonoc cattests]# cat numbers.txt |  paste -s -d+ | bc
70

But after I add them together I need to divide them by 60,something like this:

[root@server1]# cat numbers.txt |  paste -s -d+ | "new command" | bc

how can I do that?

Advertisement

Answer

bc -l <<< '('$(paste -s -d+ numbers.txt)')/60'
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement