Last active
March 12, 2020 05:07
-
-
Save poeli/5ee4445955103407d9cc37581b7e014b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# USAGE: jq -R -s -f sacct2json.jq | |
# objectify/1 takes an array of string values as inputs, converts | |
# numeric values to numbers, and packages the results into an object | |
# with keys specified by the "headers" array | |
def objectify(headers): | |
# For jq 1.4, replace the following line by: def tonumberq: .; | |
def tonumberq: tonumber? // .; | |
. as $in | |
| reduce range(0; headers|length) as $i ({}; .[headers[$i]] = ($in[$i] | tonumberq) ); | |
def sacct2table: | |
# For jq 1.4, replace the following line by: def trim: .; | |
def trim: sub("^ +";"") | sub(" +$";""); | |
split("\n") | map( split("|") | map(trim) ); | |
def sacct2json: | |
sacct2table | |
| .[0] as $headers | |
| reduce (.[1:][] | select(length > 0) ) as $row | |
( []; . + [ $row|objectify($headers) ]); | |
sacct2json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment