Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 7, 2024. It is now read-only.
/csvprintPublic archive

command line utility for printing csv files

License

NotificationsYou must be signed in to change notification settings

vegarsti/csvprint

Repository files navigation

Build StatuscodecovDownloads

A command-line utility for pretty printing csv files and converting to other formats.

Installation

If Python 3 with the package manager pip is installed, doingpip3 install csvprint in your terminal should do the trick.

Development installation

Withpipenv installed.

  1. Clone this repo
  2. Dopipenv install
  3. pipenv shell
  4. pip install -e .

Usage

csvprint [filename] prints a formatted table iffilename is a comma separated file.

» cat imdb.csvTitle,Release Year,Estimated BudgetShawshank Redemption,1994,$25 000 000The Godfather,1972,$6 000 000The Godfather: Part II,1974,$13 000 000The Dark Knight,2008,$185 000 00012 Angry Men,1957,$350 000» csvprint imdb.csvTitle                  Release Year Estimated BudgetShawshank Redemption   1994         $25 000 000The Godfather          1972         $6 000 000The Godfather: Part II 1974         $13 000 000The Dark Knight        2008         $185 000 00012 Angry Men           1957         $350 000

You can also pipe intocsvprint:

» cat imdb.csv | csvprintTitle                  Release Year Estimated BudgetShawshank Redemption   1994         $25 000 000The Godfather          1972         $6 000 000The Godfather: Part II 1974         $13 000 000The Dark Knight        2008         $185 000 00012 Angry Men           1957         $350 000

Options

CommandResult
-aspecify alignment (left or right) - see examples below
-cspecify which columns to print
-hprint help message
--markdownprint as markdown
--latexprint as latex table
--numeric [c1:d1] [c2:d2] ...specify decimal numbers for chosen numeric columns (c for column,d for digits)
--headeradd header decoration around the first line
-s 'char'file is delimited bychar (instead of comma),tab for tab
-p [n]add a padding ofn spaces for each column, on both sides
-d [string]specify the string to separate columns

Alignment example

There are three options for specifying alignment. One can usel orr for aligning all cells to the left or right, respectively. One can also specify a distinct alignment option for each column. Then the number of options will need to match the number of columns.

» csvprint imdb.csv -a l r rTitle                  Release Year Estimated BudgetShawshank Redemption           1994      $25 000 000The Godfather                  1972       $6 000 000The Godfather: Part II         1974      $13 000 000The Dark Knight                2008     $185 000 00012 Angry Men                   1957         $350 000

Markdown example

Markdown output also supports left and right alignment.

» csvprint examples/imdb.csv --markdown -a l r rTitle                  | Release Year | Estimated Budget:----------------------|-------------:|----------------:Shawshank Redemption   |         1994 |      $25 000 000The Godfather          |         1972 |       $6 000 000The Godfather: Part II |         1974 |      $13 000 000The Dark Knight        |         2008 |     $185 000 00012 Angry Men           |         1957 |         $350 000

When rendered as HTML, this looks like

TitleRelease YearEstimated Budget
Shawshank Redemption1994$25 000 000
The Godfather1972$6 000 000
The Godfather: Part II1974$13 000 000
The Dark Knight2008$185 000 000
12 Angry Men1957$350 000

Numeric example

» csvprint examples/numeric.csvmeasure1  measure21.2323    90001.299     9000001» csvprint examples/numeric.csv --numeric 1:1 2:1measure1  measure21.2       9000.01.3       9000001.0

Testing

Runpytest while in the root directory of this repository.


[8]ページ先頭

©2009-2026 Movatter.jp