Documentation
The documentation on this page is for the latest release (version 0.1) of csv2sql. You can check which version you have by running:
csv2sql -V
To view the documentation specific to a different version of csv2sql, view the README.md file that comes with your version.
You can also download the last release of csv2sql:
Usage
csv2sql [options]
Option | Description |
---|---|
-d, --database DATABASE | Database to import into. Default is "csv2sql.db" |
-e, --encoding INPUT:OUTPUT | Input and output encoding. Default is "UTF-8:UTF-8" |
-f, --file FILENAME | CSV file to import. You can alternately pipe CSV data into standard input |
-h, --help | Print this help message |
-t, --table TABLE | Table to import into. Default is the name of the file being imported from or "stdin" if CSV data is from standard input. Periods in the filename are replaced with underscores |
-v, --verbose | Print verbose output |
-V, --version | Print version number |
Examples
- Import widgets.csv into the default table (widgets_csv) and database (csv2sql.db):
csv2sql -f widgets.csv
- Import standard input into the "foo" table within the "bar.db" database:
cat widgets.csv | csv2sql -t foo -d bar.db
- Import products.csv and more-products.csv into the "products" table within the default database (csv2sql.db):
csv2sql -f products.csv -t products
csv2sql -f more-products.csv -t products
- Export data from SQLite sorted by the "ProductName" column to output.csv:
sqlite3 -header -csv csv2sql.db "SELECT * FROM products ORDER BY ProductName" > output.csv
Installation
- Verify that you have Ruby 1.9.3 (released October 2011) or later installed:
ruby --version
Earlier versions may also work, but are untested.
- Verify that you have SQLite 3.6.16 or later installed:
sqlite3 -version
- Verify that you have the sqlite3 Ruby module installed. For example, if you're using RubyGems:
gem list sqlite3
- Download and extract the tarball:
wget https://github.com/mrideout/csv2sql/archive/v0.1.tar.gz
tar -xzf v0.1.tar.gz
cd csv2sql-0.1 Make csv2sql executable:
chmod 755 csv2sql
Optionally, move **csv2sql** into a directory that's in your PATH. For example:
sudo mv csv2sql /usr/local/bin/
Contributing
Create your feature branch:
git checkout -b my-new-feature
Commit your changes:
git commit -a -m 'Add some feature'
Push to the branch:
git push origin my-new-feature
Submit a pull request.
History
Matt Rideout wrote and released csv2sql in March 2015.
License
csv2sql is open source software released under the MIT License.