Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,24 @@
/* REXX ***************************************************************
* extend in.csv to add a column containing the sum of the lines' elems
* 21.06.2013 Walter Pachl
**********************************************************************/
csv='in.csv'
Do i=1 By 1 While lines(csv)>0
l=linein(csv)
If i=1 Then
l.i=l',SUM'
Else Do
ol=l
sum=0
Do While l<>''
Parse Var l e ',' l
sum=sum+e
End
l.i=ol','sum
End
End
Call lineout csv
'erase' csv
Do i=1 To i-1
Call lineout csv,l.i
End

View file

@ -0,0 +1,19 @@
/*REXX program reads a CSV file & appends a SUM column (which is the sum of all columns)*/
parse arg iFID . /*obtain optional argument from the CL*/
if iFID=='' | iFID=="," then iFID= 'CSV_SUM.DAT' /*Not specified? Then use the default*/
call linein iFID,1,0 /*position the input file to line one.*/
/* [↑] only needed if pgm is nested. */
do rec=1 while lines(iFID)\==0 /*read the input file (all records). */
x= linein(iFid); y= translate(x, , ',') /*read a rec; change commas to blanks.*/
$= 0 /*initial the sum to zero. */
do j=1 for words(y); _= word(y, j) /*get a CSV value. */
if datatype(_, 'N') then $= $ + _ /*Numeric? Add to $.*/
else $= 'SUM' /*Not? Append "SUM".*/
end /*j*/
@.rec = x','$ /*append the sum to the record. */
end /*rec*/ /*Note: at EOF, REC ≡ # of records+1.*/
say rec-1 ' records read from: ' iFID /* [↓] this elides the need for ERASE*/
call lineout iFID,@.1,1 /*set file ptr to 1st rec., write hdr.*/
do k=2 for rec-2 /*process all the records just read. */
call lineout iFID,@.k /*write the new CSV record (has SUM). */
end /*k*/ /*stick a fork in it, we're all done.*/