Created
April 6, 2014 16:06
-
-
Save amarjen/10008046 to your computer and use it in GitHub Desktop.
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 | |
# Arguments: $1 --> Ledger source file | |
# $2 --> Year Period, eg '2013' | |
# | |
# Example: bash ledger_close_year.sh mybooks.ledger 2013 | |
# Equity report from ledger | |
ledger -f $1 equity ^Income ^Expenses -p $2 > pl.tmp | |
# Invert equity report | |
cat pl.tmp | awk 'NR==1 {print '"$2"' "/12/31 Year End Closing Entry"} NR>1 {$1=" "$1; $(NF-1)=" "$(NF-1);$NF=$NF*-1; print}' > closed.tmp | |
# Change the account name | |
sed -i 's/Opening Balances/Retained Earnings/' closed.tmp | |
# Concatenate output with books in a new file | |
cat $1 closed.tmp > $1.closed | |
# Clean temporal files | |
rm pl.tmp closed.tmp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment