Created
November 23, 2011 20:43
-
-
Save vkurup/1389840 to your computer and use it in GitHub Desktop.
Take formatted commodity output from ledger and feed it to getquote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Reads from STDIN looking for ledger-formatted commodity symbols. Uses | |
# getquote (Perl script) to lookup the lastest price for commodity, then | |
# appends to PRICEDB file. | |
# | |
# Usage: | |
# ledger -n bal ^Assets:Investments | glue-quote.sh | |
# | |
# Assumes that you have 'getquote' on your path | |
LEDGER_PRICEDB=$HOME/.pricedb | |
TOUCHED= | |
while read data; do | |
SYMBOL=`echo $data | awk '{ print $2 }'` | |
if [ $SYMBOL ] | |
then | |
PRICE=`getquote $SYMBOL` | |
DATE=$(date '+%Y/%m/%d %T') | |
echo "P $DATE $SYMBOL $PRICE" >> $LEDGER_PRICEDB | |
TOUCHED=1 | |
fi | |
done | |
if [ $TOUCHED ] | |
then | |
echo "Pricedb file at $LEDGER_PRICEDB was modified." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment