3 ms·
If you’re going to go all bash, use cut (made for it) or sed to remove the extra comma. And you could use awk to do the melt if you don’t have python and panda
by twobitshifter 3y ago
If you’re going to go all bash, use cut (made for it) or sed to remove the extra comma.
And you could use awk to do the melt if you don’t have python and pandas.
- keepamovin 3y agoI find awk to be more reliable even for simple string manipulation. Something about sed's regexes throw me for a loop!
- ninjin 3y agoIn my case it is not Bash, but POSIX shell: #!/bin/sh set -eu u=https://www.ecb.europa.eu/stats/eurofxref/eurofxref.zip ftp -Vo - $u | zcat | sed 's/, $//' | awk -F ', ' ' NR == 1 { for(i = 1; i <= NF; ++i) { col[$i] = i c = ($i != "GBP") ? $i : "EUR" printf "%s%s", c, (i < NF) ? "\t" : "\n" } } NR >= 2 { printf "%s\t", $1 for(i = 2; i <= NF; ++i) { c = (i != col["GBP"]) ? $i/$(col["GBP"]) : $i printf "%s%s", c, (i < NF) ? "\t" : "\n" } } ' Fetches the latest rates and converts the base currency to GBP and format to TSV. Then I run a cron(8) job 15~30 minutes after the release each work day and dump the output so that I can retrieve it from httpd(8) over HTTPS to be injected into my window manager status bar. A pretty elegant solution that spares the ECB from my desktops hammering their server. All with tools from the OpenBSD base install.