If you want to use the command-line (and do not create an entire program to do the job), you'd like to use rows, a project I'm working on: it's a command-line interface to tabular data but also a Python library to use in your programs. With the command-line interface you can pretty-print any data in CSV, XLS, XLSX, HTML or any other tabular format supported by the library with a simple command:
rows print myfile.csv
If myfile.csv
is like this:
state,city,inhabitants,area
RJ,Angra dos Reis,169511,825.09
RJ,Aperibé,10213,94.64
RJ,Araruama,112008,638.02
RJ,Areal,11423,110.92
RJ,Armação dos Búzios,27560,70.28
Then rows will print the contents in a beautiful way, like this:
+-------+-------------------------------+-------------+---------+
| state | city | inhabitants | area |
+-------+-------------------------------+-------------+---------+
| RJ | Angra dos Reis | 169511 | 825.09 |
| RJ | Aperibé | 10213 | 94.64 |
| RJ | Araruama | 112008 | 638.02 |
| RJ | Areal | 11423 | 110.92 |
| RJ | Armação dos Búzios | 27560 | 70.28 |
+-------+-------------------------------+-------------+---------+
Installing
If you are a Python developer and already have pip
installed on your machine, just run inside a virtualenv or with sudo
:
pip install rows
If you're using Debian:
sudo apt-get install rows
Other Cool Features
Converting Formats
You can convert between any supported format:
rows convert myfile.xlsx myfile.csv
Querying
Yes, you can use SQL into a CSV file:
$ rows query 'SELECT city, area FROM table1 WHERE inhabitants > 100000' myfile.csv
+----------------+--------+
| city | area |
+----------------+--------+
| Angra dos Reis | 825.09 |
| Araruama | 638.02 |
+----------------+--------+
Converting the output of the query to a file instead of stdout is also possible using the --output
parameter.
As a Python Library
You can you in your Python programs too:
import rows
table = rows.import_from_csv('myfile.csv')
rows.export_to_txt(table, 'myfile.txt')
# `myfile.txt` will have same content as `rows print` output
Hope you enjoy it!