Skip to content

Instantly share code, notes, and snippets.

@schoettl
Created February 8, 2019 23:08
Show Gist options
  • Save schoettl/0d459347005661bbe7691116db7be4a6 to your computer and use it in GitHub Desktop.
Save schoettl/0d459347005661bbe7691116db7be4a6 to your computer and use it in GitHub Desktop.
In hledger register output, remove running-total column and invert amount optionally (for € commodity)
#!/bin/bash
# Remove running sum and optionally invert amounts.
# Call with -i as first arg to invert amount!
# All other args are passed to hledger register.
set -o errexit -o pipefail -o nounset
removeSum() {
sed -r -e 's/ +[^ ]+ €$//'
}
invertAmount() {
awk '
/ -[0-9,.]+ €$/ {
print gensub(/(.*) -([0-9,.]+ €$)/, "\\1 \\2", 1)
next
};
/ [0-9,.]+ €$/ {
print gensub(/(.*) ([0-9,.]+ €$)/, "\\1 -\\2", 1)
next
};
1 # otherwise print'
}
main() {
if [[ $1 == -i ]]; then
shift
hledger register "$@" | removeSum | invertAmount
else
hledger register "$@" | removeSum
fi
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment