CSV data manipulation: Difference between revisions
Content added Content deleted
Walterpachl (talk | contribs) (add REXX) |
Walterpachl (talk | contribs) m (→REXX: add Header tag) |
||
Line 10: | Line 10: | ||
:4,8,12,16,20 |
:4,8,12,16,20 |
||
== |
=={{header|REXX}}== |
||
<lang rexx>/* REXX *************************************************************** |
<lang rexx>/* REXX *************************************************************** |
||
* extend in.csv to add a column containing the sum of the lines' elems |
* extend in.csv to add a column containing the sum of the lines' elems |
Revision as of 11:29, 21 June 2013
CSV data manipulation is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
CSV spreadsheet files are portable ways of storing tabular data. The CSV format is either flexible or ill defined, depending on a point of view, allowing for delimiters besides comma.
The task here is to read a CSV file, change some values and save the changes back to the same file. For this task we will use the following CSV file:
- 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
REXX
<lang rexx>/* REXX ***************************************************************
- extend in.csv to add a column containing the sum of the lines' elems
- 21.06.2013 Walter Pachl
- /
in='in.csv' out='out.csv'; 'erase' out
Do i=1 By 1 While lines(in)>0
l=linein(in) If i=1 Then Call lineout out,l',SUM' Else Do ol=l sum=0 Do While l<> Parse Var l e ',' l sum=sum+e End Call lineout out,ol','sum End End</lang>
Output
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