csvlook

Parse CSV data from STDIN and beautify output.
Like csvlook from csvkit (https://github.com/onyxfish/csvkit/)

IN

a,b,c
1,2,3

OUT

|----+---+----|
|  a | b | c  |
|----+---+----|
|  1 | 2 | 3  |
|----+---+----|

IN

title,filename,url,retrieval_date
"Event Reports for Operating Reactors",event-notification-rpt-lastmonth.txt,"http://www.data.gov/download/4028",2011-04-17
"FY 09 Education Recipients by State.",FY09_EDU_Recipients_by_State.csv,http://www.data.gov/raw/4029,2011-04-17
"FY ""10"" Education Recipients by State",Datagov_FY10_EDU_recp_by_State.csv,http://www.data.gov/raw/4509,2011-04-17

OUT

|----------------------------------------+--------------------------------------+-----------------------------------+-----------------|
|  title                                 | filename                             | url                               | retrieval_date  |
|----------------------------------------+--------------------------------------+-----------------------------------+-----------------|
|  Event Reports for Operating Reactors  | event-notification-rpt-lastmonth.txt | http://www.data.gov/download/4028 | 2011-04-17      |
|  FY 09 Education Recipients by State.  | FY09_EDU_Recipients_by_State.csv     | http://www.data.gov/raw/4029      | 2011-04-17      |
|  FY "10" Education Recipients by State | Datagov_FY10_EDU_recp_by_State.csv   | http://www.data.gov/raw/4509      | 2011-04-17      |
|----------------------------------------+--------------------------------------+-----------------------------------+-----------------|

IN

text,date,integer,boolean,float,time,datetime,empty_column,_unnamed
Chicago Tribune,1920-01-01,164,False,41800000.01,00:00:00,1920-01-01T00:00:00,,
Chicago Sun-Times,1948-01-01,63,True,1.27,14:57:13,1948-01-01T14:57:13,,Extra data past headers will be trimmed
Chicago Reader,1971-01-01,40,True,1.0,04:14:00,1971-01-01T04:14:00,,
This row has blanks,,,,,,,,
Unicode!,,,,,,,,

OUT

|----------------------+------------+---------+---------+-------------+----------+---------------------+--------------+------------------------------------------|
|  text                | date       | integer | boolean | float       | time     | datetime            | empty_column | _unnamed                                 |
|----------------------+------------+---------+---------+-------------+----------+---------------------+--------------+------------------------------------------|
|  Chicago Tribune     | 1920-01-01 | 164     | False   | 41800000.01 | 00:00:00 | 1920-01-01T00:00:00 |              |                                          |
|  Chicago Sun-Times   | 1948-01-01 | 63      | True    | 1.27        | 14:57:13 | 1948-01-01T14:57:13 |              | Extra data past headers will be trimmed  |
|  Chicago Reader      | 1971-01-01 | 40      | True    | 1.0         | 04:14:00 | 1971-01-01T04:14:00 |              |                                          |
|  This row has blanks |            |         |         |             |          |                     |              |                                          |
|  Unicode!            |            |         |         |             |          |                     |              |                                          |
|----------------------+------------+---------+---------+-------------+----------+---------------------+--------------+------------------------------------------|

IN

a,b,c
1,2,3
4,,6
5,1,7

OUT

|----+---+----|
|  a | b | c  |
|----+---+----|
|  1 | 2 | 3  |
|  4 |   | 6  |
|  5 | 1 | 7  |
|----+---+----|

Tasks with inputs that are not ASCII are REALLY annoying.

Thu Jan 15 12:48:01 2015

Sorry, I'll consider it for the future.

Fri Jan 16 11:08:45 2015

  1. My last solution hung with "testing now". It shouldn't have.
  2. My previous solution (marked "wrong" here) works perfectly on my machines (perl 5.14 and perl 5.8.8). However, it did not display the unicode character on JAGC. What is the perl version used here?

Tue Jan 20 13:03:18 2015

The hang ended with "wrong solution" Once again, the solution works perfectly with my versions of perl

Tue Jan 20 14:07:55 2015

We use perl 5.18.2 from Ubuntu 14.04. Your code works fine, I checked it manually. Probably we have a problem when transferring data from the LXC container. For now I will leave the tests only with ascii characters.

Tue Jan 20 15:07:16 2015

Thanks But the problem exists even after you removed the unicode character The table formatting looks deifferent from what I see in my terminals

Tue Jan 20 15:46:26 2015

Yes, looks very strange.

Tue Jan 20 15:50:54 2015

Sorry for long delay, but I have checked JAGC and it's works fine. JAGC will remove all trailing "\n" from any test, such your last <> in perl code return string w/o "\n".

Sun Jan 25 17:42:00 2015

WTF!! why unicode characrer was removed from tests. There are several solves on perl with this symbol.

Fri Feb 13 20:54:38 2015

JAGC has a problem with unicode for some right solutions as you can see below. So for now I removed this test.

Sat Feb 14 11:11:45 2015


Leave a comment

Parsed as Markdown

Login to leave a comment