Created
October 7, 2012 18:07
-
-
Save nuex/3849110 to your computer and use it in GitHub Desktop.
budget-calc
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
#!/usr/bin/awk -f | |
# | |
# budget-calc | |
# | |
# Builds a budget to save for upcoming bills | |
# | |
# USAGE | |
# | |
# Given a budget file like this with bill costs per month: | |
# | |
# Electric $100.00 ; 1st | |
# Credit Card $20.00 ; 5th | |
# Internet $50.00 ; 15th | |
# Auto Insurance $80.00 ; 10th | |
# CSA $80.00 ; Savings for Jan 1st 2013 | |
# Phone $60.00 ; 5th | |
# Water $25.00 ; 20th | |
# | |
# budget.awk will tell you what you need to save weekly: | |
# | |
# budget-calc budget.txt | |
# | |
# Returns: | |
# | |
# $103.75 | |
# | |
BEGIN { | |
total = 0 | |
FS="$" | |
# This is the divisor to find the amount to budget. | |
# The default is 4 (Weekly). | |
# | |
# 4: Weekly | |
# 2: Bi-Weekly | |
# 1: Monthly | |
# | |
divisor = 4 | |
} | |
# Ignore comments | |
NF == 0 || /^;/ { | |
next | |
} | |
{ | |
amount = $2 | |
sub(/\$/, "", amount) | |
sub(/\./, "", amount) | |
sub(/,/, "", amount) | |
total = total + amount | |
} | |
END { | |
budget = total / divisor | |
amount = budget / 100 | |
printf("$%0.2f\n", amount) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment