Skip to content

Instantly share code, notes, and snippets.

@blippy
Created November 6, 2016 19:41
Show Gist options
  • Select an option

  • Save blippy/034cb1ded234a523e8176d9605550d1e to your computer and use it in GitHub Desktop.

Select an option

Save blippy/034cb1ded234a523e8176d9605550d1e to your computer and use it in GitHub Desktop.
Calculating percentages using csnobol4
#!/bin/sh
exec snobol4 -b "$0" "$@"
-INCLUDE "/usr/lib/snobol4/1.4.1/bq.sno"
FLOAT = Span('01234567890.')
SPACES = Span(' ')
T = table()
input('readline', 1, , '/home/mcarter/.mcacc/work/s3/epics.rep')
mine readline 'mine' :F(mine)
norm line = readline
line 'Grand:' SPACES FLOAT . grand :S(report)
line Span(&ucase '.') . key SPACES FLOAT SPACES FLOAT SPACES FLOAT . fvalue
T[key] = fvalue :(norm)
report
A = convert(T, 'ARRAY')
idx = 0
reploop
idx = idx + 1
ticker = a[idx, 1] :F(END)
pc = 100 * A[idx,2] / grand
output = BQ('printf "%-6s %6.2f\n" "' ticker '" ' pc)
:(reploop)
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment