Skip to content

Commit

Permalink
adjust to be able to specify separator for transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
jastBytes committed Feb 18, 2024
1 parent 599bdc0 commit 4d96fdc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Go program to categorize bank transactions within a csv file based on regular ex
It's easy to use. See the [examples](/examples/) folder.

```shell
go run main.go examples/categories.csv examples/transactions.csv examples/output.csv 1
go run main.go examples/categories.csv examples/transactions.csv examples/output.csv 1 ","
```
9 changes: 6 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ type Category struct {
}

func main() {
if len(os.Args) != 5 {
fmt.Println("Usage: go run main.go categories.csv transactions.csv output.csv column_index")
if len(os.Args) != 6 {
fmt.Printf("Wrong number of arguments: %v\n", len(os.Args))
fmt.Println("Usage: go run main.go categories.csv transactions.csv output.csv column_index separator")
return
}

Expand All @@ -26,6 +27,8 @@ func main() {
return
}

separator := os.Args[5]

categoriesFile, err := os.Open(os.Args[1])
if err != nil {
fmt.Println("Error opening categories file:", err)
Expand Down Expand Up @@ -60,7 +63,7 @@ func main() {
defer transactionsFile.Close()

transactionsReader := csv.NewReader(transactionsFile)
transactionsReader.Comma = ';'
transactionsReader.Comma = rune(separator[0])
transactionsRecords, err := transactionsReader.ReadAll()
if err != nil {
fmt.Println("Error reading transactions file:", err)
Expand Down

0 comments on commit 4d96fdc

Please sign in to comment.