September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
15
Task/CSV-data-manipulation/Jq/csv-data-manipulation.jq
Normal file
15
Task/CSV-data-manipulation/Jq/csv-data-manipulation.jq
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Omit empty lines
|
||||
def read_csv:
|
||||
split("\n")
|
||||
| map(if length>0 then split(",") else empty end) ;
|
||||
|
||||
# add_column(label) adds a summation column (with the given label) to
|
||||
# the matrix representation of the CSV table, and assumes that all the
|
||||
# entries in the body of the CSV file are, or can be converted to,
|
||||
# numbers:
|
||||
def add_column(label):
|
||||
[.[0] + [label],
|
||||
(reduce .[1:][] as $line
|
||||
([]; ($line|map(tonumber)) as $line | . + [$line + [$line|add]]))[] ] ;
|
||||
|
||||
read_csv | add_column("SUM") | map(@csv)[]
|
||||
Loading…
Add table
Add a link
Reference in a new issue