Skip to content

Rishabh570/csvlang

Repository files navigation

Tests Go Report Card License: MIT Go Reference

csvlang is a dynamic language to interact with CSV files. It is a domain-specific language that allows you to read, filter, modify, and export data from CSV files easily.

Documentation about csvlang commands can be found at godoc.org.

Contents

  1. Features
  2. Usage
  3. Getting Started
  4. Running Tests
  5. Contributing
  6. License

Features

Read all or specific rows or columns

load data.csv

let rows = read row *;
let firstRow = read row 0;
let firstColumn = read row * col 0;
let filteredRows = read row * col * where age > 20;

Fill empty cells with a fallback value

load data.csv

let rows = read row * col amount where age > 20;
let polyfilledRows = fill(rows, "name", "John Doe");

Remove duplicate rows

load data.csv

let rows = read row *;

let uniqueRows = unique(rows);

Built-in statistical functions

To calculate the sum, average, and count of values in a column.

load data.csv

let rows = read row * col amount where age > 20;

let totalAmount = sum(rows);
let averageAmount = avg(rows);
let countAmount = count(rows);

Export to JSON or CSV file

load data.csv

let rows = read row * where age > 20;

save rows as output.csv;
save rows as output.json;

Usage

Option 1: Using Go (Recommended)

go install github.com/Rishabh570/csvlang@latest

Option 2: Binary Installation

  1. Download the latest binary for your platform from the releases page.
  2. Extract the archive.
  3. Add the binary to your PATH.

Option 3: Build from Source

git clone https://github.com/Rishabh570/csvlang.git
cd csvlang
go build -o csvlang

Getting Started

  1. Clone the project:
git clone https://github.com/Rishabh570/csvlang
  1. Change to the project directory:
cd csvlang
  1. Install the dependencies:
go mod tidy
  1. Create a CSV file named data.csv in the project directory with the following content:
name,age,amount
John Doe,25,1000
John Doe,25,1000
Jane Smith,30,2000
Bob Brown,28,2500
  1. Create a csvlang script named script.csvlang in the project directory with the following content:
load data.csv
let rows = read row * where age > 20;
let uniqueRows = unique(rows);
save uniqueRows as output.csv;
  1. Run the project with your csvlang script path:
go run main.go --path <path-to-csvlang-script>

or, if you have installed the binary and it is present in your PATH, you can run the following command:

csvlang --path <path-to-csvlang-script>

Running Tests

To run tests, run the following command

go test ./...

Contributing

Contributions are always welcome!

See contributing.md for ways to get started.

License

MIT

About

Process and export your CSV files through code

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published