File: more-examples.sh 1 #!/bin/sh 2 3 # more-examples.sh 4 # 5 # Here are several command-line examples using `gt` (short for `gotron`, 6 # which in turn is short for `GO TRansform jsON`). 7 # 8 # All commands should run on a linux-style shell as they are: you can even 9 # run this file as a shell script, if all goes well. 10 11 12 case "$1" in 13 -h|--h|-help|--help) 14 awk '/^# +examples\.sh/, /^$/ { gsub(/^# ?/, ""); print }' "$0" 15 exit 0 16 ;; 17 esac 18 19 20 # find out how long 4GB last when playing 16-bit PCM sounds for various 21 # settings; results then turned from seconds into HH:MM:SS-style strings 22 gt '// 16-bit/2-byte samples, mono or stereo, for both CD-audio and DAT 23 _{44_100, 48_000} * _{mono: 1, stereo: 2} * 2 & 24 25 // find how many seconds 4 GB last with those settings, playback-wise 26 (4 * gb) / _ & 27 28 // turn seconds into HH:MM:SS.SS-style strings 29 _ . dive(a(floor(v / 3600), floor(v % 3600 / 60), fix(v % 60, 2)) ^ `:`) 30 ' . 31 32 # get recent `live` exchange rates from the bank of canada, transforming 33 # values from the latest record; the trick at the end of the URI is to 34 # limit data-transfer size, by asking for records only for the current year 35 gt 'define( 36 latest, _.observations[-1], 37 rates, latest.drop(`d`), 38 ) & 39 40 // improve keys/names by removing everything around the 3-letter 41 // currency codes, then pick `v` fields, parsing them into numbers 42 rates . each(k - `FX` - `CAD`, +v.v | v) & 43 44 // rename field `d` as `date`, and use all entries from the previous 45 // step, sorted by their currency-code labels 46 merge(_{ date: latest.d }, _.sort(k)) 47 ' https://www.bankofcanada.ca/valet/observations/group/FX_RATES_DAILY/json?start_date=`date +%Y`-01-01