-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextract.sh
11 lines (11 loc) · 1.01 KB
/
extract.sh
1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash
if test -r "$1" -a -f "$1"
then
cat "$1" | jq --slurp --compact-output 'def flatten: reduce .[] as $i ([]; if $i | type == "array" then . + ($i | flatten) else . + [$i] end); [.[] | {name: .faction} ] | unique | .[]' > factions.jsonl
cat "$1" | jq --slurp --compact-output 'def flatten: reduce .[] as $i ([]; if $i | type == "array" then . + ($i | flatten) else . + [$i] end); [.[] | {name: .type} ] | unique | .[] | select(.name !=null)' > 'groups.jsonl'
cat "$1" | jq --slurp --compact-output 'def flatten: reduce .[] as $i ([]; if $i | type == "array" then . + ($i | flatten) else . + [$i] end); [.[] | {name: .variations[].rarity} ] | unique | .[]' > rarities.jsonl
cat "$1" | jq --slurp --compact-output 'def flatten: reduce .[] as $i ([]; if $i | type == "array" then . + ($i | flatten) else . + [$i] end); [.[] | .categories] | flatten | unique | to_entries | .[] | select(.value !=null) | {name: .value}' > categories.jsonl
cp "$1" cards.jsonl
else
echo "Error: File doesn't exists or can't read file."
fi