Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/CSV-data-manipulation/Jq/csv-data-manipulation.jq
Normal file
20
Task/CSV-data-manipulation/Jq/csv-data-manipulation.jq
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Input: a single row
|
||||
# Omit empty rows
|
||||
def read_csv:
|
||||
if length>0 then split(",") else empty end ;
|
||||
|
||||
# Input: an array
|
||||
# Output: the same array but with an additional summation column.
|
||||
# If .[0] is a number, then it is assumed the entire row consists of numbers or numeric strings;
|
||||
# otherwise, 0 is added
|
||||
def add_sum:
|
||||
(if .[0] | type == "number" then (map(tonumber) | add) else 0 end) as $sum
|
||||
| . + [$sum] ;
|
||||
|
||||
# `tocsv` is only needed if fields should only be quoted by necessity:
|
||||
def tocsv:
|
||||
map( if type == "string" and test("[,\"\r\n]") then "\"\(.)\"" else . end )
|
||||
| join(",");
|
||||
|
||||
( input | read_csv | . + ["SUM"] | @csv),
|
||||
(inputs | read_csv | add_sum | @csv)
|
||||
Loading…
Add table
Add a link
Reference in a new issue