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 # handle help options 13 case "$1" in 14 -h|--h|-help|--help) 15 # show help message, extracting the info-comment at the start 16 # of this file, and quit 17 awk '/^# +examples\.sh/, /^$/ { gsub(/^# ?/, ""); print }' "$0" 18 exit 0 19 ;; 20 esac 21 22 23 # find out how long 4GB last when playing 16-bit PCM sounds for various 24 # settings; results then turned from seconds into HH:MM:SS-style strings 25 gt '// 16-bit/2-byte samples, mono or stereo, for both CD-audio and DAT 26 _{44_100, 48_000} * _{mono: 1, stereo: 2} * 2 & 27 28 // find how many seconds 4 GB last with those settings, playback-wise 29 (4 * gb) / _ & 30 31 // turn seconds into HH:MM:SS.SS-style strings 32 _ . dive(a(floor(v / 3600), floor(v % 3600 / 60), fix(v % 60, 2)) ^ `:`) 33 ' . 34 35 # get recent `live` exchange rates from the bank of canada, transforming 36 # values from the latest record; the trick at the end of the URI is to 37 # limit data-transfer size, by asking for records only for the current year 38 gt 'define( 39 latest, _.observations[-1], 40 rates, latest.drop(`d`), 41 ) & 42 43 // improve keys/names by removing everything around the 3-letter 44 // currency codes, then pick `v` fields, parsing them into numbers 45 rates . each(k - `FX` - `CAD`, +v.v | v) & 46 47 // rename field `d` as `date`, and use all entries from the previous 48 // step, sorted by their currency-code labels 49 merge(_{ date: latest.d }, _.sort(k)) 50 ' https://www.bankofcanada.ca/valet/observations/group/FX_RATES_DAILY/json?start_date=`date +%Y`-01-01