For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > March 2006 > csv to ascii table conversion?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author csv to ascii table conversion?
ewaguespack@gmail.com

2006-03-27, 7:00 pm

I am going to build a csv (or colon delimited, or space delimited, etc)
to ascii table converter...


does anything like this already exist?


e.g.:


../xsv2ascii -f /etc/passwd -d ":"
________________________________
| root | x | 0 | 0 | root | /root | /bin/bash |
....

Chris F.A. Johnson

2006-03-27, 7:00 pm

On 2006-03-27, ewaguespack@gmail.com wrote:
> I am going to build a csv (or colon delimited, or space delimited, etc)
> to ascii table converter...
>
>
> does anything like this already exist?
>
>
> e.g.:
>
>
> ./xsv2ascii -f /etc/passwd -d ":"
> ________________________________
>| root | x | 0 | 0 | root | /root | /bin/bash |
> ...


Do you mean something like this:

sep=:
rep=" | "
sed -e "s/$sep/$rep/g" -e 's/^/| /' -e 's/$/ |/'

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
xhoster@gmail.com

2006-03-27, 7:00 pm

ewaguespack@gmail.com wrote:
> I am going to build a csv (or colon delimited, or space delimited, etc)
> to ascii table converter...


Can you define an "ascii table"? To me, csv tables *are* ascii tables
already. well, unless they include nonascii characters.

>
> does anything like this already exist?
>
> e.g.:
>
> ./xsv2ascii -f /etc/passwd -d ":"
> ________________________________
> | root | x | 0 | 0 | root | /root | /bin/bash |
> ...


So then, is an ascii table just a csv with all the separating commas turned
into " | ", with a "| " in front and a " |" behind?

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
bob the builder

2006-03-27, 7:00 pm

> > ./xsv2ascii -f /etc/passwd -d ":"
>
> Do you mean something like this:
>
> sep=:
> rep=" | "
> sed -e "s/$sep/$rep/g" -e 's/^/| /' -e 's/$/ |/'



well, actually more like this... and I know the text is going to be
trashed because of tabs / variable sized fonts, etc.

----------------.----------------.----------------.---------------
Host | IP Address | Management IP | iLO Address
----------------+----------------+----------------+---------------
gfd_ipcvxy | 168.178.52.28 | |
----------------+----------------+----------------+---------------
dfg_ipcvxya01 | 168.178.52.22 | | 146.171.67.29
----------------+----------------+----------------+---------------
ghk_ipcvxya02 | 168.178.52.24 | | 143.171.76.21
----------------+----------------+----------------+---------------

or this:

psql=# \d
List of relations
Schema | Name | Type | Owner
---------+----------------------------------+----------+---------
public | accounts | table | pgdba


or this:

http://www.stat.ucl.ac.be/ISpersonn...ableinASCII.jpg

bob the builder

2006-03-27, 7:00 pm

> Can you define an "ascii table"? To me, csv tables *are* ascii tables
> already. well, unless they include nonascii characters.




I guess I should say an "ascii art table"
example:
http://www.stat.ucl.ac.be/ISpersonn...ableinASCII.jpg

update:
it looks like there is something out there that does this...
http://search.cpan.org/~lunatic/Tex...e/ASCIITable.pm
although I would prefer to do it without external modules.

Bart Lateur

2006-03-27, 7:00 pm

bob the builder wrote:

>well, actually more like this... and I know the text is going to be
>trashed because of tabs / variable sized fonts, etc.
>
>----------------.----------------.----------------.---------------
>Host | IP Address | Management IP | iLO Address
>----------------+----------------+----------------+---------------
>gfd_ipcvxy | 168.178.52.28 | |
>----------------+----------------+----------------+---------------
>dfg_ipcvxya01 | 168.178.52.22 | | 146.171.67.29
>----------------+----------------+----------------+---------------
>ghk_ipcvxya02 | 168.178.52.24 | | 143.171.76.21
>----------------+----------------+----------------+---------------


Take a look at the module Text::Table,
<http://search.cpan.org/~anno/Text-T...b/Text/Table.pm>

That'll take care of the backend, converting the data into a fixed-pitch
font based, space padded, table.

You'll just need to read the data in first, the modules Text::CSV_XS, or
Text::xSV, could be helpful.

--
Bart.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com