Summarize Each Row of Integers in a Text File

Problem description & analysis

The following is text file txt.txt:

10 20 30 40 50

11 21 31 41 51

Each row in the text file contains multiple integers separated by white spaces. We are trying to sum the integers in each row. Below is the expected result:

150

155

Solution

Write the following script (p1.dfx) in esProc:

A

1

=file("result.txt").export(file("txt.txt").import@w(;," ").(~.sum()))

Explanation:

A1   Read the text file as a sequence of sequences, sum members in each sub-sequence, and export results to result.txt.

Q & A Collection

https://stackoverflow.com/questions/60704836/how-do-you-calculate-the-sum-of-integer-elements-in-an-array-using-text-files-in