Created
March 14, 2021 14:46
-
-
Save wader/b8da6b7e4fcb2202358f53cf35819380 to your computer and use it in GitHub Desktop.
jq csv and csv kv and range map
This file contains hidden or 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
| def csv: split(","); | |
| def csv_kv: [csv[] | split("=") | {(.[0]): .[1]}] | add; | |
| def obj_to_csv_kv: [to_entries[] | [.key, .value] | join("=")] | join(","); | |
| # TODO: errors? | |
| def csv_range_map: | |
| # "0-2=a,1=b" -> ["a", "b", "a"] | |
| [ csv[] | |
| | split("=") | |
| | .[1] as $c | |
| | .[0] | |
| | split(":")[] | |
| | split("-") | |
| | map(tonumber) | |
| | if (.[1] | not) then [.[0], .[0]] end | |
| | range(.[0]; .[1]+1) | |
| | [., $c] | |
| ] | |
| | reduce .[] as $r ([]; .[$r[0]] = $r[1]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment