CSV data manipulation: Difference between revisions

 
(3 intermediate revisions by 3 users not shown)
Line 1,261:
3,7,11,15,19,55
4,8,12,16,20,60</pre>
=={{header|EasyLang}}==
<syntaxhighlight>
s$ = input
print s$ & ",SUM"
repeat
s$ = input
until s$ = ""
sum = 0
for v in number strsplit s$ ","
sum += v
.
print s$ & "," & sum
.
input_data
C1,C2,C3,C4,C5
1,5,9,13,17
2,6,10,14,18
3,7,11,15,19
4,8,12,16,20
</syntaxhighlight>
{{out}}
<pre>
C1,C2,C3,C4,C5,SUM
1,5,9,13,17,45
2,6,10,14,18,50
3,7,11,15,19,55
4,8,12,16,20,60
</pre>
 
=={{header|EchoLisp}}==
<syntaxhighlight lang=scheme>
Line 3,087 ⟶ 3,116:
4,8,12,16,20,60
"</syntaxhighlight>
 
=={{header|Logo}}==
{{works with|UCB Logo|6.2.4}}
UCBLogo has no built-in support for generic CSV files.
 
<syntaxhighlight lang="logo">to csv.data.manipulation :in :out
local [header line list sum]
openread :in
setread :in
openwrite :out
setwrite :out
make "header readword
print word :header ",SUM
while [not eofp] [
make "line readword
make "list parse map [ifelse equalp ? ", ["\ ] [?]] :line
make "sum apply "sum :list
print (word :line "\, :sum)
]
close :in
setread []
close :out
setwrite []
end</syntaxhighlight>
 
<syntaxhighlight lang="logo">csv.data.manipulation "data.csv "output.csv</syntaxhighlight>
 
{{out}}
<pre>
Contents of output.csv
 
C1,C2,C3,C4,C5,SUM
1,5,9,13,17,45
2,6,10,14,18,50
3,7,11,15,19,55
4,8,12,16,20,60
</pre>
 
=={{header|Lua}}==
Line 4,905 ⟶ 4,971:
=={{header|Wren}}==
Wren does not have any built-in functions for dealing with generic CSV files so we therefore need to work from first principles.
<syntaxhighlight lang=ecmascript"wren">import "io" for File
 
var lines = File.read("rc.csv").split("\n").map { |w| w.trim() }.toList