Skip to content

Instantly share code, notes, and snippets.

@zealoushacker
Last active February 19, 2016 03:59
Show Gist options
  • Save zealoushacker/a56030258a41dad90139 to your computer and use it in GitHub Desktop.
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
#!/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