Guest User

Untitled

a guest
Dec 14th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #!/usr/bin/env Rscript
  2. library(readr)
  3. library(dplyr)
  4. library(magrittr)
  5.  
  6. args = commandArgs(trailingOnly=TRUE)
  7.  
  8. if (length(args) != 2) {
  9. stop("usage: nab2ynab.R nab.csv ynab.csv", call.=FALSE)
  10. }
  11.  
  12. infile <- args[1]
  13. outfile <- args[2]
  14.  
  15. data = read_csv(infile,skip = 6)
  16. data %<>% tbl_df
  17. ynab <-
  18. data %>%
  19. filter(grepl("^[0-9][0-9]\\.[0-9][0-9]\\.[0-9]{4}$",`Booking Date`)) %>%
  20. transmute(Date=sub("^([0-9][0-9])\\.([0-9][0-9])\\.([0-9]{4})$","\\1/\\2/\\3",`Booking Date`),
  21. Payee=sub("^([^,]*),.*$","\\1",Text),
  22. Category="",
  23. Memo=sub("^[^,]*,(.*)$","\\1",Text),
  24. Outflow=Debit,
  25. Inflow=Credit) %>%
  26. tbl_df
  27. write_csv(ynab, outfile, na="")
Add Comment
Please, Sign In to add comment