Last active
February 19, 2016 03:59
-
-
Save zealoushacker/a56030258a41dad90139 to your computer and use it in GitHub Desktop.
A quick script to clean up my bank statements from Alamosa State Bank to just extract withdrawals and deposits as CSV
This file contains hidden or 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/env ruby | |
require "csv" | |
dep_or_withd = false | |
CSV.open("statement.csv", "wb") do |csv| | |
csv<<["*Date", "*Amount", "Payee", "Description", "Reference", "Check Number"] | |
IO.foreach("./statement_dump.txt") do |line| | |
line_date = line.match(/^\d{2}\/\d{2}\/\d{2}/) | |
if line_date && (dep_or_withd) | |
amount = line.match(/\d+(?:[,.])?\d+(?:\.\d+)? \n$/)[0].sub(" \n","") | |
desc = line.sub(line_date[0], "").sub(amount, "").sub(" \n", "") | |
amount = "-#{amount}" if dep_or_withd[0] == "WITHDRAWALS" | |
csv<<[line_date,amount,"",desc.lstrip!,"","",""] | |
end | |
unless dep_or_withd | |
dep_or_withd = line.match(/DEPOSITS|WITHDRAWALS/) | |
end | |
if line.match(/_____________________________________________________________________________/) | |
dep_or_withd = false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment