awkWARD Accounting
Rick Richardson
rick at sesame.UUCP
Mon Jul 8 00:26:01 AEST 1985
The following 'shar' archive contains a simple, yet powerful
checkbook acounting system. Since it uses 'awk', it is more
portable than 'C', and is easy to modify, even by novice programmers.
-Rick Richardson ..talcott!sesame!rick
---------------------------- CUT HERE -------------------------------
#!/bin/sh
# shar: Shell Archiver
# Run the following text with /bin/sh to create:
# README
# balance
# demo
# prbook
# pracct
sed 's/^X//' << 'SHAR_EOF' > README
X awkWARD ACCOUNTING MADE EASY
X ------- ---------- ---- ----
X shareware from
X PC Research, Inc.
X
XINTRODUCTION
X------------
XThis directory contains a simple, yet powerful checkbook accounting
Xsystem, based upon 'awk(1)'. Since awk provides great power, with
Xa minimum of fuss, these tools were easily created, and are portable
Xto any machine running UNIX. The tools operate on a common database,
Xcalled the "book", which follows the format of a checkbook register.
XThe file is easily created and updated using any convenient text
Xeditor.
X
XThis package is provided as shareware. If you find this package
Xuseful or educational, you are encouraged to help support the
Xcreation of additional 'shareware packages', by making a contribution
X($10 suggested) to:
X PC Research, Inc.
X 93 Garrison Drive
X Neptune, NJ 07753
X (201) 922-1124
XawkWARD Accounting is (C) Copyright PC Research, Inc. 1985. Unlimited
Xnon-profit use of this package is hereby granted.
X
XBOOK FILE FORMAT
X----------------
XEach line in the "book" can be one of:
X
X # comment, useful for column headers to maintain sanity.
X H output page header, used to document account title/number
X c entry which has cleared the bank
X - entry which has not cleared the bank
X
XThe accounting entries are composed of 6 fields, separated by whitespace:
X
X CLEAR DATE CHECK AMOUNT ACCOUNT DESCRIPTION
X
XWhere:
X CLEAR is "c" for cleared entries, "-" for outstanding ones
X DATE is date of entry, in MM/DD/YY format
X CHECK is the check number
X AMOUNT is the amount of the entry
X ACCOUNT is any 1-7 character name for the account.
X The name "+" is special, it is for deposits.
X Account names are useful for obtaining summaries
X of all transactions of a particular type, e.g.
X "rent", "util", "food", etc. Use all lowercase,
X if possible.
X DESCRIPTION Any descriptive text you want to enter, 1-35 chars.
X The first character should be capitalized.
X
XAn example "book" file is provided in "demo". It is reproduced here:
X
X H Debbie S. Confused, In Solvent Bank #999 999 999
X #
X # Accounts:
X # + Deposit
X # rent House Rent
X # util Utilities (gas, electric, water) payments
X # food Food expenses
X #
X # Clear Date Number Amount Account Description
X # ----- ---- ------ ------ ------- -----------
X c 12/28/84 - 700 + Deposit, Sweatshop Clothiers
X c 6/1/85 101 600 rent Guido Slumlord, june rent
X c 6/1/85 102 75 food Bob's Greasy Spoon
X c 6/1/85 103 13.31 util Three Mile Island Electric
X - 6/28/85 - 700 + Deposit, Sweatshop Clothiers
X - 7/1/85 101 600 rent Guido Slumlord, june rent
X - 7/1/85 102 75 food Tanduri Rat Restaurant
X - 7/1/85 103 17.55 util Three Mile Island Electric
X
XPROGRAMS
X--------
XThree "awk(1)" programs are provided which operate upon the database.
X
X balance book [YR=yr]
X prbook book [YR=yr]
X pracct book account [YR=yr]
X
XBALANCE
X-------
XThe "balance" command is used to reconcile the "book" with the bank
Xstatement. Once per month, you edit the book, marking the entries
Xwhich have cleared the bank with a "c". Then you use "balance" to
Xcompute the banks idea of your account balance, as well as the current
X"book" balance. Your bank statement and the bank balance must agree,
Xor else the bank has made a mistake, or you've forgotten to enter
Xsomething. Additionally, running totals for all accounts are printed,
Xso you can immediately see where all the money has gone. The optional
Xparameter "YR=yy" restricts the accumlation of account totals to the
Xyear "yy" (e.g. 84).
X
XA sample run of "balance demo" follows:
X
X
XAccount Reconciliation for Debbie S. Confused, In Solvent Bank #999 999 999
X
X
XBank balance = 11.69
XCurrent balance = 19.14
X
XTotal for food = 150.00
XTotal for rent = 1200.00
XTotal for + = 1400.00
XTotal for util = 30.86
X
XPRBOOK
X------
XThe "prbook" command is used to print the "book" entries, usually
Xto a line printer. The optional parameter "YR=yy" restricts the
Xentries printed to those for year "yy". Executing "prbook demo"
Xproduces:
X
X
XCheck Transactions for Debbie S. Confused, In Solvent Bank #999 999 999, Page 1
X
XC CHEK DATE DESCRIPTION PAYMENT DEPOSIT BALANCE
X- ---- -------- ----------------------------------- ------- ------- -------
Xc - 12/28/84 Deposit, Sweatshop Clothiers 700.00 700.00
Xc 101 6/1/85 Guido Slumlord, june rent 600.00 100.00
Xc 102 6/1/85 Bob's Greasy Spoon 75.00 25.00
Xc 103 6/1/85 Three Mile Island Electric 13.31 11.69
X- - 6/28/85 Deposit, Sweatshop Clothiers 700.00 711.69
X- 101 7/1/85 Guido Slumlord, june rent 600.00 111.69
X- 102 7/1/85 Tanduri Rat Restaurant 75.00 36.69
X- 103 7/1/85 Three Mile Island Electric 17.55 19.14
X
XPRACCT
X------
XThe "pracct" command is used to print just the entries in the "book"
Xwhich are for "account". The optional "YR=yy" parameter restricts the
Xentries printed to those found during year "yy".
XExecuting "pracct demo food" produces:
X
X
Xfood Transactions for Debbie S. Confused, In Solvent Bank #999 999 999, Page 1
X
XC CHEK DATE DESCRIPTION PAYMENT DEPOSIT BALANCE
X- ---- -------- ----------------------------------- ------- ------- -------
Xc 102 6/1/85 Bob's Greasy Spoon 75.00 -75.00
X- 102 7/1/85 Tanduri Rat Restaurant 75.00 -150.00
X
XACCOUNT NAMES
X-------------
XAccount names are a very useful way to categorize expenses. If used
Xconsistently, it becomes possible to summarize all expenses for
Xa particular type of item. For example, an account called "taxded"
Xcould be used to group all tax deductable expenditures. Then, on April
X15th, you could use "pracct mybook taxded YR=85" to get a list and total
Xof all tax deductible expenditures, for Schedule A.
X
XHARDCOPY
X--------
XThe output of each of the programs has been designed to be printed directly
Xon a line printer having a page length of 66 lines. Header and trailer
Xwhitespace is automatically supplied. Thus there is no need to use
Xan additional filter to prepare the output for the printer. Simply
Xuse the command:
X prbook | lp
Xon UNIX System V and derivatives, or
X prbook | lpr
Xon UNIX Version 7 and derivatives.
X
XIf your lineprinter has a page length other than 66 lines, you may
Xmodify "pracct" and "prbook" to adjust for this. Simply change the
Xthe number "58" in the line:
X if ( (ln % 58) == 0)
Xso that the number is the page length of your printer minus eight.
X
XNOTES
X-----
XThe whitespace in the command files themselves has been compressed
Xwhen necessary, in order to allow operation on systems which
Xrestrict the UNIX command line length to a smaller number of
Xcharacters than is usual (e.g. Venix/86). The "YR" option depends
Xupon using a relatively new version of "awk(1)". On older UNIX
Xreleases, this option may not operate at all, although all other
Xfeatures should operate normally.
X
XUse the comment feature to replicate the column headers for the "book"
Xevery 24 lines, so they will always be visible when editing the file.
X
XDue to implementation restrictions, it is best to use all lowercase
Xfor account names, and to capitalize the first letter of the
Xdescription for an entry in the "book". Otherwise, surprises may
Xresult.
X
X"awk(1)" has poor error diagnostics. No sanity checking is performed
Xupon the format of the "book". A bad "book" means garbage out.
X
XThe speed of the commands is a direct function of the length of the
X"book". When the execution time becomes unacceptable, you may
Xwant to split the "book" into pieces, placing previous years data
Xin another file. Don't forget to make an initial "Carryover from
Xprevious year" deposit to the current "book".
X
XIf you type "pracct mybook", and do not specify an account, a list
Xof all accounts is printed. This feature can be used to remind
Xyourself of the accounts you have defined. You should periodically
Xcheck this list to make sure that you have not duplicated an account
Xunder another name. The number of accounts is essentially unlimited,
Xbut for esthetic reasons it is usually a good idea to limit the number
Xof accounts. It is suggested that you list the accounts you have
Xdefined as comments in the beginning of the "book" file.
X
XYou should endeavor to enter items into the "book" in date order,
Xrather than by check number. Otherwise, you may be surprised by the
Xoutput of "prbook" when year selection is used.
SHAR_EOF
sed 's/^X//' << 'SHAR_EOF' > balance
X: awkWARD Accounting Made Easy
X: [C] Copyright PC Research, Inc. 1985
X:
X: balance book [YR=yy]:
X: print balances of all accounts [for year yy].
X:
X: FILE FORMAT:
X: CLEAR DATE CHECK AMOUNT ACCOUNT COMMENT
X: # ignored
X: c mm/dd/yy nnnn dddd.cc name cleared bank
X: - mm/dd/yy nnnn dddd.cc name not cleared bank
X: H page header line
X:
XBOOK=$1;
Xif [ ! -f "$BOOK" ]
Xthen
X echo "usage: balance book [YR=yy]"
X exit 1;
Xfi
Xshift; OPTS="$*"
Xawk '
X{
X if ($1 == "#")
X continue;
X else if ($1 == "H")
X {
X printf "\n\nAccount Reconciliation for %s\n", substr($0, 3)
X continue;
X }
X if ($5 == "+")
X {
X if ($1 == "c")
X bank += $4;
X curr += $4;
X }
X else
X {
X if ($1 == "c")
X bank -= $4;
X curr -= $4;
X }
X yr=split($2, date, "/"); if (YR != "" && date[yr] != YR) continue;
X expense[$5] += $4;
X}
XEND {
X printf "\n\n"
X printf "Bank balance = %8.2f\n", bank
X printf "Current balance = %8.2f\n\n", curr
X for (acctnum in expense)
X if (YR != "")
X printf "19%s Total for %-8s = %8.2f\n",\
X YR, acctnum,expense[acctnum]
X else
X printf "Total for %-8s = %8.2f\n",\
X acctnum,expense[acctnum]
X}' $OPTS $BOOK
SHAR_EOF
sed 's/^X//' << 'SHAR_EOF' > demo
XH Debbie S. Confused, In Solvent Bank #999 999 999
X#
X# Accounts:
X# + Deposit
X# rent House Rent
X# util Utilities (gas, electric, water) payments
X# food Food expenses
X#
X# Clear Date Number Amount Account Description
X# ----- ---- ------ ------ ------- -----------
Xc 12/28/84 - 700 + Deposit, Sweatshop Clothiers
Xc 6/1/85 101 600 rent Guido Slumlord, june rent
Xc 6/1/85 102 75 food Bob's Greasy Spoon
Xc 6/1/85 103 13.31 util Three Mile Island Electric
X- 6/28/85 - 700 + Deposit, Sweatshop Clothiers
X- 7/1/85 101 600 rent Guido Slumlord, june rent
X- 7/1/85 102 75 food Tanduri Rat Restaurant
X- 7/1/85 103 17.55 util Three Mile Island Electric
SHAR_EOF
sed 's/^X//' << 'SHAR_EOF' > prbook
X: awkWARD Accounting Made Easy
X: [C] Copyright PC Research, Inc. 1985
X:
X: prbook book [YR=yy]: print checkbook [for year yy]
X: FILE FORMAT
X: CLEAR DATE CHECK AMOUNT ACCOUNT COMMENT
XBOOK=$1;
Xif [ ! -f "$BOOK" ]
Xthen
X echo "usage: prbook book [YR=yy]"
X exit 1;
Xfi
Xshift; OPTS="$*"
Xawk '
X{
X if ($1 == "#")
X continue;
X if ( $1 == "H" )
X {
X h = "Check Transactions for " substr($0, 3);
X continue;
X }
X yr=split($2, date, "/");
X if (YR != "" && date[yr] != YR)
X { if ($5 == "+") cur += $4; else cur -= $4; continue; }
X l = substr($0, index($0, $6));
X if ( (ln % 58) == 0)
X {
X if (ln != 0) printf "\n\n"
X printf "\n\n%s, Page %d\n\n", h, ln/58+1
X printf "C CHEK DATE %-35s PAYMENT DEPOSIT BALANCE\n",\
X "DESCRIPTION"
X printf "- ---- -------- %-35s ------- ------- -------\n",\
X "-----------------------------------"
X }
X if ($5 == "+")
X {
X cur += $4;
X printf "%s %4s %8s %-35s %8s %8.2f %8.2f\n",$1,$3,$2,l,"",$4,cur
X }
X else
X {
X cur -= $4;
X printf "%s %4s %8s %-35s %8.2f %8s %8.2f\n",$1,$3,$2,l,$4,"",cur
X }
X ++ln
X}' $OPTS $BOOK
SHAR_EOF
sed 's/^X//' << 'SHAR_EOF' > pracct
X: awkWARD Accounting Made Easy
X: [C] Copyright PC Research, Inc. 1985
X:
X: pracct book account [YR=yy]:
X: print 'account' transactions for 'book' [for year yy].
X: FILE FORMAT
X: CLEAR DATE CHECK AMOUNT ACCOUNT COMMENT
Xif [ "$#" = 0 ]
Xthen
X echo "usage: pracct book account [YR=yy]"
X exit 1;
Xfi
XBOOK=$1; shift
Xif [ "$1" = "" ]
Xthen
X echo "usage: pracct book account [YR=yy]"
X echo " accounts for $BOOK:"
X awk '
X {
X if ($1 == "#")
X continue;
X account[$5] = 1
X }
X END {
X for (acctnum in account)
X printf "\t\t%s\n", acctnum
X }' $BOOK
X exit 1;
Xfi
XACCT=$1; shift
XOPTS="$*"
Xawk '
X{
X if ($1=="H") { h = ACCT " Transactions for " substr($0,3); continue; }
X if ($1=="#" || $5!=ACCT) continue;
X yr = split($2,date,"/"); if (YR!="" && YR!=date[yr]) continue;
X l = substr($0,index($0,$6));
X if ((ln%58)==0)
X {
X if (ln!=0) printf "\n\n"
X printf "\n\n%s, Page %d\n\n", h, ln/58+1
X printf "C CHEK DATE %-35s PAYMENT DEPOSIT BALANCE\n",\
X "DESCRIPTION"
X printf "- ---- -------- %-35s ------- ------- -------\n",\
X "-----------------------------------"
X }
X if ($5=="+")
X {
X cur+=$4;
X printf "%s %4s %8s %-35s %8s %8.2f %8.2f\n",$1,$3,$2,l,"",$4,cur
X }
X else
X {
X cur-=$4;
X printf "%s %4s %8s %-35s %8.2f %8s %8.2f\n",$1,$3,$2,l,$4,"",cur
X }
X ++ln
X}' $OPTS "ACCT=$ACCT" $BOOK
SHAR_EOF
exit
--
Rick Richardson, PC Research, Inc.
{genrad|ihnp4|ima}!wjh12!talcott!sesame!{rick|pcrat!rick}
{cbosgd|harvard}!talcott!sesame!{rick|pcrat!rick}
rick%sesame at harvard.ARPA
More information about the Comp.sources.unix
mailing list