Tuesday, February 6, 2024

[SOLVED] more than one source of data to process with bc

Issue

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?


Solution

bc -l <<< '('$(paste -s -d+ numbers.txt)')/60'


Answered By - choroba
Answer Checked By - Robin (WPSolving Admin)