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.
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProcSPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL